diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 7851b9eb1e5d6..3da6ab1e13f2e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -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 diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 969a08efed4ae..3f2841bae8805 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -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