Skip to content

Commit

Permalink
don't stop at cannot definitions when there are no conditions - closes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Oct 4, 2010
1 parent 12037d7 commit 8f49f28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cancan/can_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def matches_conditions?(action, subject, extra_args)
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

Expand Down
7 changes: 7 additions & 0 deletions spec/cancan/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@
@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
Expand Down

0 comments on commit 8f49f28

Please sign in to comment.