Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Fixed bug where conditions on an optionally associated object would t…
Browse files Browse the repository at this point in the history
…hrow exceptions if the associated object was not present at the rule match time.
  • Loading branch information
thatothermitch committed Apr 1, 2011
1 parent 7bcfd3d commit 6aaab9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cancan/rule.rb
Expand Up @@ -109,7 +109,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
if attribute.kind_of? Array
attribute.any? { |element| matches_conditions_hash? element, value }
else
matches_conditions_hash? attribute, value
!attribute.nil? && matches_conditions_hash?(attribute, value)
end
elsif value.kind_of?(Array) || value.kind_of?(Range)
value.include? attribute
Expand Down
7 changes: 7 additions & 0 deletions spec/cancan/ability_spec.rb
Expand Up @@ -249,6 +249,13 @@
@ability.can?(:read, 1..5).should be_true
@ability.can?(:read, 4..6).should be_false
end

it "should not match subjects return nil for methods that must match nested a nested conditions hash" do
mock(object_with_foo = Object.new).foo { :bar }
@ability.can :read, Array, :first => { :foo => :bar }
@ability.can?(:read, [object_with_foo]).should be_true
@ability.can?(:read, []).should be_false
end

it "should not stop at cannot definition when comparing class" do
@ability.can :read, Range
Expand Down

0 comments on commit 6aaab9e

Please sign in to comment.