spec/slavery_spec.rb in slavery-1.3.0 vs spec/slavery_spec.rb in slavery-1.4.0

- old
+ new

@@ -51,10 +51,25 @@ Slavery.stub(:disabled).and_return(true) Slavery.on_slave { User.slaveryable?.should == false } end + it 'sets the Slavery database spec name by configuration' do + Slavery.spec_key = "custom_slave" + Slavery.spec_key.should eq 'custom_slave' + + Slavery.spec_key = lambda{ + "kewl_slave" + } + Slavery.spec_key.should eq "kewl_slave" + + Slavery.spec_key = lambda{ + "#{Slavery.env}_slave" + } + Slavery.spec_key.should eq "test_slave" + end + it 'works with scopes' do User.count.should == 2 User.on_slave.count.should == 1 # Why where(nil)? @@ -76,17 +91,17 @@ User.instance_variable_set :@slave_connection_holder, @old_conn ActiveRecord::Base.configurations = @old_config end it 'connects to master if slave configuration not specified' do - ActiveRecord::Base.configurations['test_slave'] = nil + ActiveRecord::Base.configurations[Slavery.spec_key] = nil Slavery.on_slave { User.count }.should == 2 end it 'raises error when no configuration found' do ActiveRecord::Base.configurations['test'] = nil - ActiveRecord::Base.configurations['test_slave'] = nil + ActiveRecord::Base.configurations[Slavery.spec_key] = nil expect { Slavery.on_slave { User.count } }.to raise_error(Slavery::Error) end end end