Sha256: ed5ca5f503cd70747969cd636352989fd9a20c09ad18469e0996e4b02ccc2643

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

describe ConnectionManager::SecondaryConnectionBuilder do
  
  context '#database_name' do
    it "should return the name of the database the model is using" do
      Fruit.database_name.should eql('cm_test')
    end
  end

  context '#other_association_options' do
    
      it "should add :class_name options set to the replication subclass if :class_name is blank" do
        options = Fruit.secondary_association_options(:has_one, :plant, 'Slave')
        options[:class_name].should eql("Plant::Slave")
      end
      
      it "should append :class_name with the replication subclass if :class_name is not bank" do
        options = Fruit.secondary_association_options(:has_one, :plant, 'Slave', :class_name => 'Plant')
        options[:class_name].should eql("Plant::Slave")
      end
    
    context "has_one or has_many" do
    it "should add the :foreign_key if the :foreign_key options is not present" do
      options = Fruit.secondary_association_options(:has_one, :plant, 'Slave')
      options[:foreign_key].should eql('fruit_id')
      options = Fruit.secondary_association_options(:has_many, :plant, 'Slave')
      options[:foreign_key].should eql('fruit_id')
    end
    end
  end
  
  context '#secondary_connection_classes' do
    it "should return the :using array with the array elements classified and append with Connection" do
     Fruit.secondary_connection_classes({:using => ['slave_1_test_db','slave_2_test_db']}).
        should eql(["Slave1TestDbConnection", "Slave2TestDbConnection"])
    end
    
  end
  
  context '#replicated' do
    it "should raise an exception if no replication_connection_classes are found" do
      Fruit.stubs(:secondary_connection_classes).returns([])
      lambda { Fruit.replicated }.should raise_error
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
connection_manager-0.2.1 spec/lib/secondary_connection_builder_spec.rb