ryanb/cancan — pull request #714 by iamvery (2012-08-10 15:26:29+00:00)
Title: Fetched records should match the most liberally defined ability

I ran into what appears to be a regression occurring somewhere between 1.6.5 and 1.6.8. Basically, I had defined abilities in my app something like this:

if user.role? :admin
can :manage, :all
elsif user.role? :other
#...
end

can :manage, Something, :user_id => user.id

The purpose of this is to say, "Admins can do anything, other users with roles can do 'such and such', and all users can manage their own Somethings". In 1.6.5 this worked great, with the `accessible_by` method returned "owned" models for general users and all models for admins. In 1.6.8 it would essentially "prefer" the last defined ability and only return "owned" models for every user (including admins).

I believe this has to do with the "mergeable conditions" feature introduced at some point. It doesn't take into account that there is a "super condition" in effect if it determines the conditions are not mergeable. Attached is a pull request with spec that fixes my problem, but it may or may not be the best solution due to my limited understanding / experience w/ this code. Also, I haven't used data mapper or mongoid, so I didn't even attempt to address any issues there.

As always, thanks for the GREAT lib!