Sha256: 4bb9bb8cca8febaf2ea7674f83b2c45b8435d106803b1d0656f64517fcd68cd8

Contents?: true

Size: 707 Bytes

Versions: 3

Compression:

Stored size: 707 Bytes

Contents

require 'minitest_helper'

describe ActiveRecord::PgReconnect do

  let(:connection) do
    ActiveRecord::Base.establish_connection 'postgres://postgres:password@localhost:5432/postgres'
    ActiveRecord::Base.connection
  end

  it 'Reconnect after fail' do
    refute connection.reconnection_required?

    connection.execute 'SELECT 1'

    refute connection.reconnection_required?

    connection.raw_connection.stub(:async_exec, ->(*args) { raise PG::ConnectionBad }) do
      assert_raises(ActiveRecord::StatementInvalid) { connection.execute 'SELECT 1' }
    end

    assert connection.reconnection_required?

    connection.execute 'SELECT 1'

    refute connection.reconnection_required?
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_record-pg_reconnect-2.0.0 spec/reconnection_spec.rb
active_record-pg_reconnect-1.0.1 spec/reconnection_spec.rb
active_record-pg_reconnect-1.0.0 spec/reconnection_spec.rb