From ba01349eb0e1b3ea8b08f7761cb9145702051ded Mon Sep 17 00:00:00 2001 From: Florent Piteau Date: Wed, 29 Feb 2012 15:49:19 +0100 Subject: [PATCH] Don't remove key-value from the subject hash we might want to use it again. --- lib/cancan/rule.rb | 2 +- spec/cancan/ability_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/cancan/rule.rb b/lib/cancan/rule.rb index 44c14af..4e6bee2 100644 --- a/lib/cancan/rule.rb +++ b/lib/cancan/rule.rb @@ -123,7 +123,7 @@ module CanCan 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 diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index 48b6782..30bf3ad 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -298,6 +298,14 @@ describe CanCan::Ability do @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