don't stop at cannot definitions when there are no conditions - closes #161

This commit is contained in:
Ryan Bates 2010-10-04 11:11:14 -07:00
parent 12037d7f43
commit 8f49f28713
2 changed files with 9 additions and 1 deletions

View File

@ -36,7 +36,8 @@ module CanCan
elsif @conditions.kind_of?(Hash) && !subject_class?(subject) elsif @conditions.kind_of?(Hash) && !subject_class?(subject)
matches_conditions_hash?(subject) matches_conditions_hash?(subject)
else else
@base_behavior # Don't stop at "cannot" definitions when there are conditions.
@conditions.empty? ? true : @base_behavior
end end
end end

View File

@ -258,6 +258,13 @@ describe CanCan::Ability do
@ability.can?(:read, Range).should be_true @ability.can?(:read, Range).should be_true
end end
it "should stop at cannot definition when no hash is present" do
@ability.can :read, :all
@ability.cannot :read, Range
@ability.can?(:read, 1..5).should be_false
@ability.can?(:read, Range).should be_false
end
it "should allow to check ability for Module" do it "should allow to check ability for Module" do
module B; end module B; end
class A; include B; end class A; include B; end