Permalink
Browse files

Merge pull request #564 from flop/master

False positives on multiple nested abilities definitions
  • Loading branch information...
2 parents d117624 + ba01349 commit b73bd062a81eb3d9631bdb450160141012f2bd31 @ryanb committed May 10, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/cancan/rule.rb
  2. +8 −0 spec/cancan/ability_spec.rb
View
2 lib/cancan/rule.rb
@@ -123,7 +123,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
end
def nested_subject_matches_conditions?(subject_hash)
- parent, child = subject_hash.shift
+ parent, child = subject_hash.first
matches_conditions_hash?(parent, @conditions[parent.class.name.downcase.to_sym] || {})
end
View
8 spec/cancan/ability_spec.rb
@@ -306,6 +306,14 @@ class A; include B; end
@ability.can?(:read, 123 => Range).should be_true
end
+ it "passing a hash of subjects with multiple definitions should check permissions correctly" do
+ @ability.can :read, Range, :string => {:length => 4}
+ @ability.can [:create, :read], Range, :string => {:upcase => 'FOO'}
+ @ability.can?(:read, "foo" => Range).should be_true
+ @ability.can?(:read, "foobar" => Range).should be_false
+ @ability.can?(:read, 1234 => Range).should be_true
+ end
+
it "should allow to check ability on Hash-like object" do
class Container < Hash; end
@ability.can :read, Container

0 comments on commit b73bd06

Please sign in to comment.