diff --git a/lib/cancan/can_definition.rb b/lib/cancan/can_definition.rb index 6ce9e8e..071bc03 100644 --- a/lib/cancan/can_definition.rb +++ b/lib/cancan/can_definition.rb @@ -36,7 +36,8 @@ module CanCan elsif @conditions.kind_of?(Hash) && !subject_class?(subject) matches_conditions_hash?(subject) else - @base_behavior + # Don't stop at "cannot" definitions when there are conditions. + @conditions.empty? ? true : @base_behavior end end diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index 6e80dee..1f7fce9 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -258,6 +258,13 @@ describe CanCan::Ability do @ability.can?(:read, Range).should be_true 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 module B; end class A; include B; end