Merge pull request #564 from flop/master

False positives on multiple nested abilities definitions
This commit is contained in:
Ryan Bates 2012-05-10 10:59:08 -07:00
commit b73bd062a8
2 changed files with 9 additions and 1 deletions

View File

@ -123,7 +123,7 @@ module CanCan
end end
def nested_subject_matches_conditions?(subject_hash) 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] || {}) matches_conditions_hash?(parent, @conditions[parent.class.name.downcase.to_sym] || {})
end end

View File

@ -306,6 +306,14 @@ describe CanCan::Ability do
@ability.can?(:read, 123 => Range).should be_true @ability.can?(:read, 123 => Range).should be_true
end 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 it "should allow to check ability on Hash-like object" do
class Container < Hash; end class Container < Hash; end
@ability.can :read, Container @ability.can :read, Container