From 33dc653466c0058740611259956712a9027801b3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Aug 2015 13:40:55 -0700 Subject: raise if `anchor` is passed to `scope` The `anchor` parameter [is overridden](https://github.com/rails/rails/blob/b4b4a611d0eb9aa1c640c5f521c6a43bf2a65bab/actionpack/lib/action_dispatch/routing/mapper.rb#L1528) unless it is directly passed to `match`, so setting it in a scope must be a mistake. --- actionpack/lib/action_dispatch/routing/mapper.rb | 4 ++++ actionpack/test/dispatch/mapper_test.rb | 9 +++++++++ 2 files changed, 13 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 887b5957df..b80720218f 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -788,6 +788,10 @@ module ActionDispatch except: options.delete(:except) } end + if options.key? :anchor + raise ArgumentError, 'anchor is ignored unless passed to `match`' + end + @scope.options.each do |option| if option == :blocks value = block diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 6ce0e34ec3..8734380008 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -44,6 +44,15 @@ module ActionDispatch Mapper.new FakeSet.new end + def test_scope_raises_on_anchor + fakeset = FakeSet.new + mapper = Mapper.new fakeset + assert_raises(ArgumentError) do + mapper.scope(anchor: false) do + end + end + end + def test_blows_up_without_via fakeset = FakeSet.new mapper = Mapper.new fakeset -- cgit v1.2.3