Skip to content

Instantly share code, notes, and snippets.

@BDQ
Created March 20, 2012 18:22
Show Gist options
  • Save BDQ/2139167 to your computer and use it in GitHub Desktop.
Save BDQ/2139167 to your computer and use it in GitHub Desktop.
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