mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix NameError
when an invalid :on
option is given to a route
Fix the following error. ``` /Users/9sako6/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/rails-366c8f081d8b/actionpack/lib/action_dispatch/routing/mapper.rb:1865:in `map_match': undefined local variable or method `on' for #<ActionDispatch::Routing::Mapper:0x00007fd78a132bf8> (NameError) ```
This commit is contained in:
parent
366c8f081d
commit
4af50dfd95
2 changed files with 11 additions and 1 deletions
|
@ -1861,7 +1861,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def map_match(paths, options)
|
def map_match(paths, options)
|
||||||
if options[:on] && !VALID_ON_OPTIONS.include?(options[:on])
|
if (on = options[:on]) && !VALID_ON_OPTIONS.include?(on)
|
||||||
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
|
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,16 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_raising_error_when_invalid_on_option_is_given
|
||||||
|
fakeset = FakeSet.new
|
||||||
|
mapper = Mapper.new fakeset
|
||||||
|
error = assert_raise ArgumentError do
|
||||||
|
mapper.get "/foo", on: :invalid_option
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal "Unknown scope :invalid_option given to :on", error.message
|
||||||
|
end
|
||||||
|
|
||||||
def test_scope_does_not_destructively_mutate_default_options
|
def test_scope_does_not_destructively_mutate_default_options
|
||||||
fakeset = FakeSet.new
|
fakeset = FakeSet.new
|
||||||
mapper = Mapper.new fakeset
|
mapper = Mapper.new fakeset
|
||||||
|
|
Loading…
Reference in a new issue