2010-04-21 00:02:28 +00:00
|
|
|
require "spec_helper"
|
|
|
|
|
2010-12-21 18:41:55 +00:00
|
|
|
# Most of Rule functionality is tested in Ability specs
|
|
|
|
describe CanCan::Rule do
|
2010-04-21 00:02:28 +00:00
|
|
|
before(:each) do
|
|
|
|
@conditions = {}
|
2010-12-21 18:41:55 +00:00
|
|
|
@rule = CanCan::Rule.new(true, :read, Integer, @conditions, nil)
|
2010-04-21 00:02:28 +00:00
|
|
|
end
|
2010-05-21 20:41:24 +00:00
|
|
|
|
2010-04-21 00:02:28 +00:00
|
|
|
it "should return no association joins if none exist" do
|
2010-12-21 18:41:55 +00:00
|
|
|
@rule.associations_hash.should == {}
|
2010-04-21 00:02:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return no association for joins if just attributes" do
|
|
|
|
@conditions[:foo] = :bar
|
2010-12-21 18:41:55 +00:00
|
|
|
@rule.associations_hash.should == {}
|
2010-04-21 00:02:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return single association for joins" do
|
|
|
|
@conditions[:foo] = {:bar => 1}
|
2010-12-21 18:41:55 +00:00
|
|
|
@rule.associations_hash.should == {:foo => {}}
|
2010-04-21 00:02:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return multiple associations for joins" do
|
|
|
|
@conditions[:foo] = {:bar => 1}
|
|
|
|
@conditions[:test] = {1 => 2}
|
2010-12-21 18:41:55 +00:00
|
|
|
@rule.associations_hash.should == {:foo => {}, :test => {}}
|
2010-04-21 00:02:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return nested associations for joins" do
|
|
|
|
@conditions[:foo] = {:bar => {1 => 2}}
|
2010-12-21 18:41:55 +00:00
|
|
|
@rule.associations_hash.should == {:foo => {:bar => {}}}
|
2010-04-21 00:02:28 +00:00
|
|
|
end
|
2010-08-18 23:04:08 +00:00
|
|
|
|
2010-05-21 00:06:10 +00:00
|
|
|
it "should return no association joins if conditions is nil" do
|
2010-12-21 18:41:55 +00:00
|
|
|
rule = CanCan::Rule.new(true, :read, Integer, nil, nil)
|
|
|
|
rule.associations_hash.should == {}
|
2010-05-21 00:06:10 +00:00
|
|
|
end
|
2010-04-21 00:02:28 +00:00
|
|
|
end
|