Skip to content

Commit 5462fbd

Browse files
authored
Merge pull request rails#43211 from 9sako6/fix_nameerror_when_an_invalid_option_is_given_to_on
Fix `NameError` when an invalid `:on` option is given to a route
2 parents fdf5e00 + 4af50df commit 5462fbd

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)