From 8f49f287138f4026a27b465d8e6d6b73248be2d8 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Mon, 4 Oct 2010 11:11:14 -0700 Subject: [PATCH] don't stop at cannot definitions when there are no conditions - closes #161 --- lib/cancan/can_definition.rb | 3 ++- spec/cancan/ability_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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