Skip to content
  • Petrik's avatar
    0409ed57
    Clean up checks to see if DidYouMean is defined · 0409ed57
    Petrik authored
    As of Ruby 2.7 DidYouMean is included as a default gem, so there is no
    need to check if DidYouMean is defined in the test suite. We still need
    to check if the DidYouMean modules are defined in the actual code, as
    someone might run Rails with DidYouMean disabled by using the
    `--disable-did_you_mean` flag. This is ussually done for performance
    reasons.
    
    This commit also includes some of the changes made by Yuki in:
    https://github.com/rails/rails/pull/39555
    
    
    These changes include replacing Jaro with the more accurate
    SpellChecker, and using DidYouMean::Correctable for simplere
    corrections.
    
    The DidYouMean::SpellChecker does have a treshold for corrections.
    If there is not enough similarity it might not return a suggestion.
    To stop the tests from failing some test data had to be changed.
    
    For example, `non_existent` does not meet the treshold for `hello`, but
    `ello` does:
    
    DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('non_existent')
    => []
    DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('ello')
    => ["hello"]
    
    The treshold makes sense for spelling errors. But maybe we should add a
    different SpellChecker that helps to get a suggestion even if there is
    little overlap. For example for when a model only has 2 attributes
    (title and body), it's helpful to get a suggestion for `name`
    
    Co-Authored-By: default avatarYuki Nishijima <yk.nishijima@gmail.com>
    0409ed57
    Clean up checks to see if DidYouMean is defined
    Petrik authored
    As of Ruby 2.7 DidYouMean is included as a default gem, so there is no
    need to check if DidYouMean is defined in the test suite. We still need
    to check if the DidYouMean modules are defined in the actual code, as
    someone might run Rails with DidYouMean disabled by using the
    `--disable-did_you_mean` flag. This is ussually done for performance
    reasons.
    
    This commit also includes some of the changes made by Yuki in:
    https://github.com/rails/rails/pull/39555
    
    
    These changes include replacing Jaro with the more accurate
    SpellChecker, and using DidYouMean::Correctable for simplere
    corrections.
    
    The DidYouMean::SpellChecker does have a treshold for corrections.
    If there is not enough similarity it might not return a suggestion.
    To stop the tests from failing some test data had to be changed.
    
    For example, `non_existent` does not meet the treshold for `hello`, but
    `ello` does:
    
    DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('non_existent')
    => []
    DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('ello')
    => ["hello"]
    
    The treshold makes sense for spelling errors. But maybe we should add a
    different SpellChecker that helps to get a suggestion even if there is
    little overlap. For example for when a model only has 2 attributes
    (title and body), it's helpful to get a suggestion for `name`
    
    Co-Authored-By: default avatarYuki Nishijima <yk.nishijima@gmail.com>
Loading