don't pass action into can block with :manage option - closes #129

This commit is contained in:
Ryan Bates 2010-09-02 14:29:49 -07:00
parent 6105edc6a7
commit b1fb179aaf
2 changed files with 5 additions and 15 deletions

View File

@ -26,7 +26,7 @@ module CanCan
# Matches the block or conditions hash # Matches the block or conditions hash
def matches_conditions?(action, subject, extra_args) def matches_conditions?(action, subject, extra_args)
if @block && subject.class != Class if @block && subject.class != Class
call_block(action, subject, extra_args) @block.call(subject, *extra_args)
elsif @conditions.kind_of?(Hash) && subject.class != Class elsif @conditions.kind_of?(Hash) && subject.class != Class
matches_conditions_hash?(subject) matches_conditions_hash?(subject)
else else
@ -91,13 +91,5 @@ module CanCan
end end
end end
end end
def call_block(action, subject, extra_args)
block_args = []
block_args << action if @expanded_actions.include?(:manage)
block_args << (subject.class == Class ? nil : subject)
block_args += extra_args
@block.call(*block_args)
end
end end
end end

View File

@ -56,9 +56,8 @@ describe CanCan::Ability do
@block_called.should be_false @block_called.should be_false
end end
it "should pass action and object for global manage actions" do it "should pass only object for global manage actions" do
@ability.can :manage, Array do |action, object| @ability.can :manage, Array do |object|
action.should == :stuff
object.should == [1, 2] object.should == [1, 2]
@block_called = true @block_called = true
end end
@ -80,9 +79,8 @@ describe CanCan::Ability do
@ability.can?(:increment, 123).should be_true @ability.can?(:increment, 123).should be_true
end end
it "should return block result for action, object_class, and object for any action" do it "should return block result and only pass object for any action" do
@ability.can :manage, :all do |action, object| @ability.can :manage, :all do |object|
action.should == :foo
object.should == 123 object.should == 123
@block_called = true @block_called = true
end end