Skip to content

Commit 4af50df

Browse files
committed
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) ```
1 parent 366c8f0 commit 4af50df

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ def path_scope(path)
18611861
end
18621862

18631863
def map_match(paths, options)
1864-
if options[:on] && !VALID_ON_OPTIONS.include?(options[:on])
1864+
if (on = options[:on]) && !VALID_ON_OPTIONS.include?(on)
18651865
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
18661866
end
18671867

actionpack/test/dispatch/mapper_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ def test_raising_error_when_rack_app_is_not_passed
193193
end
194194
end
195195

196+
def test_raising_error_when_invalid_on_option_is_given
197+
fakeset = FakeSet.new
198+
mapper = Mapper.new fakeset
199+
error = assert_raise ArgumentError do
200+
mapper.get "/foo", on: :invalid_option
201+
end
202+
203+
assert_equal "Unknown scope :invalid_option given to :on", error.message
204+
end
205+
196206
def test_scope_does_not_destructively_mutate_default_options
197207
fakeset = FakeSet.new
198208
mapper = Mapper.new fakeset

0 commit comments

Comments
 (0)