Sha256: 60d4d58764560e52323f25aa430b85d2c67a22430eb25636c1e025ec00a8c407

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'

class FirstMigration < Landable::Migration
  self.verbose = false
  def up
    execute 'CREATE SCHEMA test_schema; SET SEARCH_PATH TO test_schema,public;'
  end
end

class RegularMigration < ActiveRecord::Migration
  self.verbose = false
  def up
    execute 'CREATE SCHEMA test_schema; SET SEARCH_PATH TO test_schema,public;'
  end
end

describe Landable::Migration do
  describe 'migrate' do
    let(:connection) { ActiveRecord::Base.connection }

    before(:each) do
      ActiveRecord::Base.connection_pool.should_receive(:with_connection).and_yield(connection)
    end

    def connection_search_path
      Landable::Migration.connection_search_path connection
    end

    context 'Landable::Migration' do
      it 'should reset the search_path to the original schema_search_path' do
        default_search_path = connection_search_path

        connection.schema_search_path = 'public'
        FirstMigration.migrate(:up)
        connection_search_path.should eq 'public'

        connection.schema_search_path = default_search_path
      end
    end

    context 'ActiveRecord::Migration' do
      it 'should NOT reset the search_path to the original schema_search_path' do
        connection.schema_search_path = 'public'

        connection_search_path.should eq 'public'
        RegularMigration.migrate(:up)
        connection_search_path.should_not eq 'public'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
landable-1.14.0 spec/lib/landable/migration_spec.rb
landable-1.13.2 spec/lib/landable/migration_spec.rb