Skip to content

Commit

Permalink
raise if anchor is passed to scope
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tenderlove committed Aug 13, 2015
1 parent b4b4a61 commit 33dc653
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,10 @@ def scope(*args)
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
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/dispatch/mapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def test_initialize
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
Expand Down

0 comments on commit 33dc653

Please sign in to comment.