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: Yuki Nishijima <yk.nishijima@gmail.com>
* Don't attach UJS form submission handlers to Turbo forms
Allows for easier migration of apps written for UJS, such that new work can be done with Turbo forms that are marked with data-turbo=true.
* Fix duplicate selectors
* Proper fix take 2
Both methods are defined in multiple parts of the framework. It would
be useful to put them in a proper place, so that repetition is
avoided.
I chose the implementation from `ActiveRecord` because it's a bit more
complete with the `SQLCounter` class, and also because other parts
depend on it.
before https://github.com/rails/rails/pull/40125 test names would be
set to "test" after this change controller_name was nil when using
ActionView::TestCase.
This returns ActionView::TestCase to previous behavior returning "test"
Add failing test for views with trailing newlines
Add and test config option
Move config option to config/application.rb
Move implementation to ERB template handler
Move config option to ActionView::Template::Handlers::ERB
When dealing with the "details" for a template: locale, format,
variant, and handler, previously we would store these in an ad-hoc way
every place we did. Often as a hash or as separate instance variables on
a class.
This PR attempts to simplify this by encapsulating known details on a
template in a new ActionView::TemplateDetails class, and requested
details in ActionView::TemplateDetails::Requested.
This allowed extracting and simplifying filtering and sorting logic from
the Resolver class as well as extracting default format logic from
UnboundTemplate.
As well as reducing complexity, in the future this should make it
possible to provide suggestions on missing template errors due to
mismatched details, and might allow improved performance.
At least for now these new classes are private (:nodoc)
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
This is called on every render or template lookup.
lookup_context = ActionController::Base.new.lookup_context
normalize = lookup_context.method(:normalize_name)
Benchmark.ips do |x|
x.report "already normalized" do
normalize.call("show", ["users"])
end
x.report "without prefixes" do
normalize.call("users/show", [])
end
x.report "with prefixes in both arguments" do
normalize.call("extra/show", ["users", "application"])
end
end
Before:
already normalized 2.322M (± 0.5%) i/s - 11.615M in 5.003512s
without prefixes 1.613M (± 0.7%) i/s - 8.076M in 5.007165s
with prefixes in both arguments
1.020M (± 0.7%) i/s - 5.154M in 5.054101s
After:
already normalized 3.740M (± 0.3%) i/s - 18.715M in 5.003477s
without prefixes 2.197M (± 0.6%) i/s - 11.089M in 5.047800s
with prefixes in both arguments
1.244M (± 0.9%) i/s - 6.246M in 5.020968s
url_for supports building polymorphic URLs via an array
of arguments (usually symbols and records). If an array is passed,
strings can result in unwanted route helper calls.
CVE-2021-22885
`codespell` works with a small custom dictionary and seems to find perhaps more spelling mistakes than `misspell` which really only fixes commonly misspelled English words.
Not all spell checkers can check all file types and most spell checkers can't find all the errors.
https://github.com/codespell-project/codespellhttps://pypi.org/project/codespell/
A default value can be a string that needs interpolation, Hash that
needs resolution via the `:count` option, or a Proc that needs
evaluation. Therefore, pass default values through `I18n.translate` to
handle these cases.
Fixes#26032.
Fixes#41277.
Fixes#41380.