Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Rules order #672

Closed
maxprokopiev opened this issue Jun 30, 2012 · 3 comments
Closed

Rules order #672

maxprokopiev opened this issue Jun 30, 2012 · 3 comments

Comments

@maxprokopiev
Copy link

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
      end

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
        end
      end
    end

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?

@andhapp
Copy link
Collaborator

andhapp commented Jun 30, 2012

@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.

@maxprokopiev
Copy link
Author

I've added pull request, but question about a new behaviour is still here

@andhapp
Copy link
Collaborator

andhapp commented Jul 4, 2012

@Juggler: Will close this as you've opened a pull request.

@andhapp andhapp closed this as completed Jul 4, 2012
maxprokopiev pushed a commit to maxprokopiev/cancan that referenced this issue Jul 5, 2012
ryanb added a commit that referenced this issue Feb 22, 2013
Changes rules order in mongoid specs. Fixes #672
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants