Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Rules order #672

Closed
maxprokopiev opened this Issue · 3 comments

2 participants

@maxprokopiev

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
Collaborator

@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 maxprokopiev referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@maxprokopiev

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

@andhapp
Collaborator

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

@andhapp andhapp closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.