Expose replica_postgresql_connection to ActiveRecord::Base.

This commit is contained in:
Guo Xiang Tan
2017-11-23 09:52:42 +08:00
parent 82222e8d18
commit a509f466a0
2 changed files with 24 additions and 20 deletions

View File

@@ -6,11 +6,11 @@ describe ActiveRecord::ConnectionHandling do
let(:replica_port) { 6432 }
let(:config) do
ActiveRecord::Base.configurations[Rails.env].merge(
"adapter" => "postgresql_fallback",
"replica_host" => replica_host,
"replica_port" => replica_port
).symbolize_keys!
ActiveRecord::Base.connection_config.merge(
adapter: "postgresql_fallback",
replica_host: replica_host,
replica_port: replica_port
)
end
let(:multisite_db) { "database_2" }
@@ -27,7 +27,6 @@ describe ActiveRecord::ConnectionHandling do
let(:postgresql_fallback_handler) { PostgreSQLFallbackHandler.instance }
before do
skip("Disable these tests until we figure out what is leaking connections")
postgresql_fallback_handler.initialized = true
['default', multisite_db].each do |db|
@@ -48,6 +47,7 @@ describe ActiveRecord::ConnectionHandling do
context 'when master server is down' do
before do
skip("Figure out why this test leaks connections")
@replica_connection = mock('replica_connection')
end
@@ -70,8 +70,8 @@ describe ActiveRecord::ConnectionHandling do
ActiveRecord::Base.expects(:postgresql_connection).with(configuration).raises(PG::ConnectionBad)
ActiveRecord::Base.expects(:verify_replica).with(@replica_connection)
ActiveRecord::Base.expects(:postgresql_connection).with(configuration.merge(
host: replica_host, port: replica_port)
ActiveRecord::Base.expects(:postgresql_connection).with(
configuration.dup.merge(host: replica_host, port: replica_port)
).returns(@replica_connection)
end
@@ -129,10 +129,9 @@ describe ActiveRecord::ConnectionHandling do
it 'should raise the right error' do
ActiveRecord::Base.expects(:postgresql_connection).with(config).raises(PG::ConnectionBad)
ActiveRecord::Base.expects(:postgresql_connection).with(config.dup.merge(
host: replica_host,
port: replica_port
)).raises(PG::ConnectionBad).once
ActiveRecord::Base.expects(:postgresql_connection).with(
config.dup.merge(host: replica_host, port: replica_port)
).raises(PG::ConnectionBad).once
postgresql_fallback_handler.expects(:verify_master).twice