Fix accessible_by for Mongoid documents when no ability is defined.
The previous spec that checked for this was not right, since there were no documents in the collection, so every query would return an empty result.
This commit is contained in:
parent
ab82dcbc8f
commit
25bf479f48
|
@ -86,7 +86,7 @@ module CanCan
|
|||
if query.conditions.blank?
|
||||
# this query is sure to return no results
|
||||
# we need this so there is a Mongoid::Criteria object to return, since an empty array would cause problems
|
||||
where({:_id => {'$exists' => true, '$type' => 2}})
|
||||
where({:_id => {'$exists' => false, '$type' => 7}}) # type 7 is an ObjectID (default for _id)
|
||||
else
|
||||
where(query.conditions)
|
||||
end
|
||||
|
|
|
@ -51,6 +51,10 @@ describe CanCan::MongoidAdditions do
|
|||
end
|
||||
|
||||
it "should return [] when no ability is defined so no records are found" do
|
||||
@model_class.create :title => 'Sir'
|
||||
@model_class.create :title => 'Lord'
|
||||
@model_class.create :title => 'Dude'
|
||||
|
||||
@model_class.accessible_by(@ability, :read).should == []
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user