Merge pull request #645 from andhapp/issue-644
Allow users to specify a mix of can and cannot rule for mongoid
This commit is contained in:
commit
7bf683d8f4
|
@ -30,8 +30,9 @@ module CanCan
|
|||
else
|
||||
# we only need to process can rules if
|
||||
# there are no rules with empty conditions
|
||||
rules = @rules.reject { |rule| rule.conditions.empty? }
|
||||
rules = @rules.reject { |rule| rule.conditions.empty? && rule.base_behavior }
|
||||
process_can_rules = @rules.count == rules.count
|
||||
|
||||
rules.inject(@model_class.all) do |records, rule|
|
||||
if process_can_rules && rule.base_behavior
|
||||
records.or rule.conditions
|
||||
|
|
|
@ -73,6 +73,17 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
|
|||
MongoidProject.accessible_by(@ability, :read).entries.should == [sir]
|
||||
end
|
||||
|
||||
it "should return the correct records when a mix of can and cannot rules in defined ability" do
|
||||
@ability.can :manage, MongoidProject, :title => 'Sir'
|
||||
@ability.cannot :destroy, MongoidProject
|
||||
|
||||
sir = MongoidProject.create(:title => 'Sir')
|
||||
lord = MongoidProject.create(:title => 'Lord')
|
||||
dude = MongoidProject.create(:title => 'Dude')
|
||||
|
||||
MongoidProject.accessible_by(@ability, :destroy).entries.should == [sir]
|
||||
end
|
||||
|
||||
it "should be able to mix empty conditions and hashes" do
|
||||
@ability.can :read, MongoidProject
|
||||
@ability.can :read, MongoidProject, :title => 'Sir'
|
||||
|
|
Loading…
Reference in New Issue
Block a user