Sha256: c585909a97ae3f922729c95be9cc61f18944b99c5668fc31da757a8fce9bb5c5

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

require "spec_helper"

# Most of CanDefinition functionality is tested in Ability specs
describe CanCan::CanDefinition do
  before(:each) do
    @conditions = {}
    @can = CanCan::CanDefinition.new(true, :read, Integer, @conditions, nil)
  end

  it "should return no association joins if none exist" do
    @can.associations_hash.should == {}
  end

  it "should return no association for joins if just attributes" do
    @conditions[:foo] = :bar
    @can.associations_hash.should == {}
  end

  it "should return single association for joins" do
    @conditions[:foo] = {:bar => 1}
    @can.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 => {}}
  end

  it "should return nested associations for joins" do
    @conditions[:foo] = {:bar => {1 => 2}}
    @can.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}
  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}
  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}
  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 == {}
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cancan-1.4.1 spec/cancan/can_definition_spec.rb
cancan-1.4.0 spec/cancan/can_definition_spec.rb
cancan-1.4.0.beta1 spec/cancan/can_definition_spec.rb