Sha256: fca8ab5b36d67a2256cdb0f230ebf686981ec8ce18fd7dfcf1ef3807d7e4e17c

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'
require 'active_record'

describe ActiveConnection do
  before(:all) do
    PG_SPEC = {
      adapter:  'postgresql',
      host:     'localhost',
      database: 'schema_test'
    }

    ActiveRecord::Base.establish_connection(PG_SPEC.merge(database: 'postgres'))
    ActiveRecord::Base.connection.drop_database('schema_test')
    ActiveRecord::Base.connection.create_database('schema_test')
    ActiveRecord::Base.establish_connection(PG_SPEC)
    ActiveRecord::Base.connection.create_schema('nonsense')
  end

  it 'changes the schema search path inside the block' do
    ActiveConnection.schema_search_path('nonsense') do
      expect(ActiveRecord::Base.connection.schema_search_path).to eq('nonsense')
    end
  end

  it 'resets the schema search path after the block has executed' do
    original_search_path = ActiveRecord::Base.connection.schema_search_path

    ActiveConnection.schema_search_path('nonsense') { }

    expect(ActiveRecord::Base.connection.schema_search_path).to eq(original_search_path)
  end

  it 'resets the schema search path after an error has occurred' do
    original_search_path = ActiveRecord::Base.connection.schema_search_path
    ActiveConnection.schema_search_path('nonsense') { break }

    expect(ActiveRecord::Base.connection.schema_search_path).to eq(original_search_path)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_connection-0.0.3 spec/active_connection_spec.rb
active_connection-0.0.2 spec/active_connection_spec.rb
active_connection-0.0.1 spec/active_connection_spec.rb