Skip to content

Commit

Permalink
Merge pull request #43211 from 9sako6/fix_nameerror_when_an_invalid_o…
Browse files Browse the repository at this point in the history
…ption_is_given_to_on

Fix `NameError` when an invalid `:on` option is given to a route
  • Loading branch information
kamipo committed Sep 14, 2021
2 parents fdf5e00 + 4af50df commit 5462fbd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -1861,7 +1861,7 @@ def path_scope(path)
end

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"
end

Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/dispatch/mapper_test.rb
Expand Up @@ -193,6 +193,16 @@ def test_raising_error_when_rack_app_is_not_passed
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
fakeset = FakeSet.new
mapper = Mapper.new fakeset
Expand Down

0 comments on commit 5462fbd

Please sign in to comment.