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

Added support for value to be Enumerable #607

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 @@ -111,7 +111,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
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
Expand Down
10 changes: 9 additions & 1 deletion spec/cancan/ability_spec.rb
Expand Up @@ -249,7 +249,15 @@
@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 }
Expand Down