Merge pull request #607 from Mixbook/master

Added support for value to be Enumerable
This commit is contained in:
Ryan Bates 2012-05-10 09:25:59 -07:00
commit 6e8bc851be
2 changed files with 10 additions and 2 deletions

View File

@ -111,7 +111,7 @@ module CanCan
else else
!attribute.nil? && matches_conditions_hash?(attribute, value) !attribute.nil? && matches_conditions_hash?(attribute, value)
end end
elsif value.kind_of?(Array) || value.kind_of?(Range) elsif value.kind_of?(Enumerable)
value.include? attribute value.include? attribute
else else
attribute == value attribute == value

View File

@ -250,6 +250,14 @@ describe CanCan::Ability do
@ability.can?(:read, 4..6).should be_false @ability.can?(:read, 4..6).should be_false
end 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 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 } mock(object_with_foo = Object.new).foo { :bar }
@ability.can :read, Array, :first => { :foo => :bar } @ability.can :read, Array, :first => { :foo => :bar }