Created
March 20, 2012 18:22
-
-
Save BDQ/2139167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "ActiveRecord::ConnectionAdapters::ConnectionHandler" do | |
let(:config){ Apartment::Test.config['connections']['mysql'].symbolize_keys } | |
let(:database){ Apartment::Test.next_db } | |
let(:database2){ Apartment::Test.next_db } | |
before do | |
Apartment.use_postgres_schemas = false | |
ActiveRecord::Base.establish_connection config | |
Apartment::Database.stub(:config).and_return config | |
end | |
context "when switching connections" do | |
before do | |
Apartment::Database.create database rescue nil | |
Apartment::Database.create database2 rescue nil | |
end | |
after do | |
Apartment::Database.drop database rescue nil | |
Apartment::Database.drop database2 rescue nil | |
end | |
it "connection pool should return same connection for model" do | |
Apartment::Database.switch(database) | |
db1_conn_a = ActiveRecord::Base.connection.object_id | |
Apartment::Database.switch(database2) | |
Apartment::Database.switch(database) | |
db1_conn_b = ActiveRecord::Base.connection.object_id | |
db1_conn_a.should == db1_conn_b | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment