You can clone with
HTTPS or Subversion.
While developing mongo_mapper adapter I've found this pending example in mongoid specs:
it "is able to mix empty conditions and hashes" do
pending "TODO figure out why this isn't working"
@ability.can :read, :mongoid_projects
@ability.can :read, :mongoid_projects, :title => 'Sir'
sir = MongoidProject.create(:title => 'Sir')
lord = MongoidProject.create(:title => 'Lord')
MongoidProject.accessible_by(@ability, :read).count.should == 2
It's related to this line in Ability class:
def relevant_rules(action, subject, attribute = nil)
specificity = 0
rules.reverse.each_with_object() do |rule, relevant_rules|
rule.expanded_actions = expand_aliases(:actions, rule.actions)
rule.expanded_subjects = expand_aliases(:subjects, rule.subjects)
if rule.relevant?(action, subject, attribute) && rule.specificity >= specificity
specificity = rule.specificity if rule.base_behavior
relevant_rules << rule
If we just change order of can rules (applying more general rule in the end), then example will pass.
So the question is - is it a bug or just a new behaviour?
@juggler: I didn't write this code, so I need to look into this a little but if you think what you are suggesting is going to fix the issue, then open a pull request and we'll look at it then. Thanks.
I've added pull request, but question about a new behaviour is still here
@juggler: Will close this as you've opened a pull request.
Fix mongoid example according to ability precedence. Closes #672