Closed al closed 11 years ago
Ah, sorry. More careful reading of the source tells me that this method should be receiving conditions as a Hash
, not Mongoid::Criteria
, so I guess this lays the blame on either CanCan or my usage of it.
I'll close this.
Some advice would be appreciated though. In this line from CanCan's Mongoid adapter, rule.conditions
is a Mongoid::Criteria
. Changing it to records.or rule.conditions.selector
seems to solve my problem. Does that sound like the right thing to do from Origin's perspective?
I've encountered what I think might be a bug in Origin. See the stack trace at the bottom of this ticket.
I'm arriving at it through a slightly unusual set of CanCan abilities, but I don't think they are the issue.
A minimal app demonstrating the problem is here: https://github.com/al/mongoid_cancan_bug. To reproduce run:
Then visit http://localhost:3000/profiles.json. You should see the error.
It arises from the fact that I have two applicable rules in abilities.rb. This is easily confirmed by removing one or other of the rules.
Digging through the stack trace lead me to this line in the
Mergeable#__multi__
method.The method is receiving an array of
Criteria
, however as soon asflatten
is applied theCriteria
are being resolved to actual matching documents (in this caseProfile
). This seems to surprise the rest of the method which evidently expects to still have an array ofCriteria
.Removing the
flatten
will progress execution to line 134, where something similar seems to be happening.Is this a bug or is there something unacceptable about the
Criteria
I am sending Mongoid/Origin's way via my CanCan abilities?Cheers