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

False positives on multiple nested abilities definitions #564

Merged
merged 1 commit into from May 10, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cancan/rule.rb
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions spec/cancan/ability_spec.rb
Expand Up @@ -298,6 +298,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
Expand Down