Augments Mongoid adapter by handling case where attribute is an array
This commit is contained in:
parent
18c1007d3f
commit
17c52a7983
|
@ -6,7 +6,14 @@ module CanCan
|
|||
end
|
||||
|
||||
def self.override_conditions_hash_matching?(subject, conditions)
|
||||
conditions.any? { |k,v| !k.kind_of?(Symbol) }
|
||||
conditions.any? do |k,v|
|
||||
key_is_not_symbol = lambda { !k.kind_of?(Symbol) }
|
||||
subject_value_is_array = lambda do
|
||||
subject.respond_to?(k) && subject.send(k).is_a?(Array)
|
||||
end
|
||||
|
||||
key_is_not_symbol.call || subject_value_is_array.call
|
||||
end
|
||||
end
|
||||
|
||||
def self.matches_conditions_hash?(subject, conditions)
|
||||
|
|
|
@ -42,6 +42,15 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
|
|||
@ability.should be_able_to(:read, model)
|
||||
end
|
||||
|
||||
it "should be able to read hashes when field is array" do
|
||||
one_to_three = MongoidProject.create(:numbers => ['one', 'two', 'three'])
|
||||
two_to_five = MongoidProject.create(:numbers => ['two', 'three', 'four', 'five'])
|
||||
|
||||
@ability.can :foo, MongoidProject, :numbers => 'one'
|
||||
@ability.should be_able_to(:foo, one_to_three)
|
||||
@ability.should_not be_able_to(:foo, two_to_five)
|
||||
end
|
||||
|
||||
it "should return [] when no ability is defined so no records are found" do
|
||||
MongoidProject.create(:title => 'Sir')
|
||||
MongoidProject.create(:title => 'Lord')
|
||||
|
|
Loading…
Reference in New Issue
Block a user