renaming CanDefinition to Rule

This commit is contained in:
Ryan Bates
2010-12-21 10:41:55 -08:00
parent a6959c0ab2
commit 37c149182c
8 changed files with 59 additions and 59 deletions

View File

@@ -32,7 +32,7 @@ describe CanCan::Ability do
@ability.can?(:read, Symbol).should be_true
end
it "should pass to previous can definition, if block returns false or nil" do
it "should pass to previous rule, if block returns false or nil" do
@ability.can :read, Symbol
@ability.can :read, Integer do |i|
i < 5
@@ -144,7 +144,7 @@ describe CanCan::Ability do
@ability.can?(:update, 123).should be_false
end
it "should support custom objects in the can definition" do
it "should support custom objects in the rule" do
@ability.can :read, :stats
@ability.can?(:read, :stats).should be_true
@ability.can?(:update, :stats).should be_false
@@ -165,7 +165,7 @@ describe CanCan::Ability do
@ability.can?(:read, 123).should be_false
end
it "should pass to previous can definition, if block returns false or nil" do
it "should pass to previous rule, if block returns false or nil" do
@ability.can :read, :all
@ability.cannot :read, Integer do |int|
int > 10 ? nil : ( int > 5 )

View File

@@ -15,19 +15,19 @@ describe CanCan::Query do
@ability.query(:read, Project).conditions.should == { :blocked => false, :user_id => 1 }
end
it "should merge multiple can definitions into single SQL string joining with OR" do
it "should merge multiple rules into single SQL string joining with OR" do
@ability.can :read, Project, :blocked => false
@ability.can :read, Project, :admin => true
@ability.query(:read, Project).conditions.should == "(admin=true) OR (blocked=false)"
end
it "should merge multiple can definitions into single SQL string joining with OR and AND" do
it "should merge multiple rules into single SQL string joining with OR and AND" do
@ability.can :read, Project, :blocked => false, :active => true
@ability.can :read, Project, :admin => true
@ability.query(:read, Project).conditions.should orderlessly_match("(blocked=false AND active=true) OR (admin=true)")
end
it "should merge multiple can definitions into single SQL string joining with OR and AND" do
it "should merge multiple rules into single SQL string joining with OR and AND" do
@ability.can :read, Project, :blocked => false, :active => true
@ability.can :read, Project, :admin => true
@ability.query(:read, Project).conditions.should orderlessly_match("(blocked=false AND active=true) OR (admin=true)")
@@ -77,7 +77,7 @@ describe CanCan::Query do
@ability.query(:read, Project).conditions.should == 'true=true'
end
it "should have nil joins if no can definitions" do
it "should have nil joins if no rules" do
@ability.query(:read, Project).joins.should be_nil
end

View File

@@ -1,57 +1,57 @@
require "spec_helper"
# Most of CanDefinition functionality is tested in Ability specs
describe CanCan::CanDefinition do
# Most of Rule functionality is tested in Ability specs
describe CanCan::Rule do
before(:each) do
@conditions = {}
@can = CanCan::CanDefinition.new(true, :read, Integer, @conditions, nil)
@rule = CanCan::Rule.new(true, :read, Integer, @conditions, nil)
end
it "should return no association joins if none exist" do
@can.associations_hash.should == {}
@rule.associations_hash.should == {}
end
it "should return no association for joins if just attributes" do
@conditions[:foo] = :bar
@can.associations_hash.should == {}
@rule.associations_hash.should == {}
end
it "should return single association for joins" do
@conditions[:foo] = {:bar => 1}
@can.associations_hash.should == {:foo => {}}
@rule.associations_hash.should == {:foo => {}}
end
it "should return multiple associations for joins" do
@conditions[:foo] = {:bar => 1}
@conditions[:test] = {1 => 2}
@can.associations_hash.should == {:foo => {}, :test => {}}
@rule.associations_hash.should == {:foo => {}, :test => {}}
end
it "should return nested associations for joins" do
@conditions[:foo] = {:bar => {1 => 2}}
@can.associations_hash.should == {:foo => {:bar => {}}}
@rule.associations_hash.should == {:foo => {:bar => {}}}
end
it "should tableize correctly for absurdly complex permissions" do
@conditions[:unit] = {:property=>{:landlord=>{:weasle_id=>560}}}
@conditions[:test] = 1
@can.tableized_conditions.should == {:units => {:properties => {:landlords=>{:weasle_id=>560}}}, :test => 1}
@rule.tableized_conditions.should == {:units => {:properties => {:landlords=>{:weasle_id=>560}}}, :test => 1}
end
it "should tableize correctly for complex permissions" do
@conditions[:unit] = {:property=>{:landlord_id=>560}}
@conditions[:test] = 1
@can.tableized_conditions.should == {:units => {:properties => {:landlord_id=>560}}, :test => 1}
@rule.tableized_conditions.should == {:units => {:properties => {:landlord_id=>560}}, :test => 1}
end
it "should return table names in conditions for association joins" do
@conditions[:foo] = {:bar => 1}
@conditions[:test] = 1
@can.tableized_conditions.should == {:foos => {:bar => 1}, :test => 1}
@rule.tableized_conditions.should == {:foos => {:bar => 1}, :test => 1}
end
it "should return no association joins if conditions is nil" do
can = CanCan::CanDefinition.new(true, :read, Integer, nil, nil)
can.associations_hash.should == {}
rule = CanCan::Rule.new(true, :read, Integer, nil, nil)
rule.associations_hash.should == {}
end
end