skip block when only class is passed to ability check, also don't pass class to block for :all - closes #116
This commit is contained in:
parent
04b523eea4
commit
6105edc6a7
|
@ -25,7 +25,7 @@ module CanCan
|
|||
|
||||
# Matches the block or conditions hash
|
||||
def matches_conditions?(action, subject, extra_args)
|
||||
if @block
|
||||
if @block && subject.class != Class
|
||||
call_block(action, subject, extra_args)
|
||||
elsif @conditions.kind_of?(Hash) && subject.class != Class
|
||||
matches_conditions_hash?(subject)
|
||||
|
@ -95,7 +95,6 @@ module CanCan
|
|||
def call_block(action, subject, extra_args)
|
||||
block_args = []
|
||||
block_args << action if @expanded_actions.include?(:manage)
|
||||
block_args << (subject.class == Class ? subject : subject.class) if @subjects.include?(:all)
|
||||
block_args << (subject.class == Class ? nil : subject)
|
||||
block_args += extra_args
|
||||
@block.call(*block_args)
|
||||
|
|
|
@ -38,9 +38,8 @@ describe CanCan::Ability do
|
|||
@ability.can?(:read, 6).should be_false
|
||||
end
|
||||
|
||||
it "should pass class with object if :all objects are accepted" do
|
||||
@ability.can :preview, :all do |object_class, object|
|
||||
object_class.should == Fixnum
|
||||
it "should not pass class with object if :all objects are accepted" do
|
||||
@ability.can :preview, :all do |object|
|
||||
object.should == 123
|
||||
@block_called = true
|
||||
end
|
||||
|
@ -48,14 +47,13 @@ describe CanCan::Ability do
|
|||
@block_called.should be_true
|
||||
end
|
||||
|
||||
it "should pass class with no object if :all objects are accepted and class is passed directly" do
|
||||
@ability.can :preview, :all do |object_class, object|
|
||||
object_class.should == Hash
|
||||
object.should be_nil
|
||||
it "should not call block when only class is passed, only return true" do
|
||||
@block_called = false
|
||||
@ability.can :preview, :all do |object|
|
||||
@block_called = true
|
||||
end
|
||||
@ability.can?(:preview, Hash)
|
||||
@block_called.should be_true
|
||||
@ability.can?(:preview, Hash).should be_true
|
||||
@block_called.should be_false
|
||||
end
|
||||
|
||||
it "should pass action and object for global manage actions" do
|
||||
|
@ -83,9 +81,8 @@ describe CanCan::Ability do
|
|||
end
|
||||
|
||||
it "should return block result for action, object_class, and object for any action" do
|
||||
@ability.can :manage, :all do |action, object_class, object|
|
||||
@ability.can :manage, :all do |action, object|
|
||||
action.should == :foo
|
||||
object_class.should == Fixnum
|
||||
object.should == 123
|
||||
@block_called = true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user