Fix broken condition in PostgresqlFallbackAdapter.
This commit is contained in:
parent
e542884b00
commit
9540b952fd
|
@ -119,7 +119,14 @@ module ActiveRecord
|
|||
|
||||
def verify_replica(connection)
|
||||
value = connection.raw_connection.exec("SELECT pg_is_in_recovery()").values[0][0]
|
||||
raise "Replica database server is not in recovery mode." if value == 'f'
|
||||
|
||||
if !value
|
||||
begin
|
||||
raise "Replica database server is not in recovery mode."
|
||||
ensure
|
||||
connection.close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -96,8 +96,15 @@ describe ActiveRecord::ConnectionHandling do
|
|||
|
||||
expect(ActiveRecord::Base.connection_pool.connections.count).to eq(0)
|
||||
|
||||
expect(ActiveRecord::Base.connection)
|
||||
.to be_an_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
||||
ActiveRecord::Base.connection_handler.clear_active_connections!
|
||||
connection = ActiveRecord::Base.connection
|
||||
|
||||
begin
|
||||
expect(connection)
|
||||
.to be_an_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
||||
ensure
|
||||
connection.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,6 +122,16 @@ describe ActiveRecord::ConnectionHandling do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.verify_replica' do
|
||||
describe 'when database is not in recovery' do
|
||||
it 'should raise the right error' do
|
||||
expect do
|
||||
ActiveRecord::Base.send(:verify_replica, ActiveRecord::Base.connection)
|
||||
end.to raise_error(RuntimeError, "Replica database server is not in recovery mode.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def with_multisite_db(dbname)
|
||||
RailsMultisite::ConnectionManagement.expects(:current_db).returns(dbname).at_least_once
|
||||
yield
|
||||
|
|
Loading…
Reference in New Issue