diff --git a/lib/cancan/rule.rb b/lib/cancan/rule.rb index 44c14af..27355bd 100644 --- a/lib/cancan/rule.rb +++ b/lib/cancan/rule.rb @@ -111,7 +111,7 @@ module CanCan else !attribute.nil? && matches_conditions_hash?(attribute, value) end - elsif value.kind_of?(Array) || value.kind_of?(Range) + elsif value.kind_of?(Enumerable) value.include? attribute else attribute == value diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index 48b6782..a99aea5 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -249,7 +249,15 @@ describe CanCan::Ability do @ability.can?(:read, 1..5).should be_true @ability.can?(:read, 4..6).should be_false end - + + it "should accept a set as a condition value" do + mock(object_with_foo_2 = Object.new).foo { 2 } + mock(object_with_foo_3 = Object.new).foo { 3 } + @ability.can :read, Object, :foo => [1, 2, 5].to_set + @ability.can?(:read, object_with_foo_2).should be_true + @ability.can?(:read, object_with_foo_3).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 }