Sha256: ba89eaec8760a551cc6ad3c52d2bba0055018f30043ba39afd3a97506774618c

Contents?: true

Size: 1.78 KB

Versions: 17

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

describe 'Ridgepole::Client#diff -> migrate', condition: '>= 5.1.0' do
  let(:actual_dsl) do
    erbh(<<-ERB)
      create_table "employees", id: false, force: :cascade do |t|
        t.string "name"
      end
    ERB
  end

  before do
    subject.diff('').migrate
    subject.diff(actual_dsl).migrate
  end
  subject { client(allow_pk_change: allow_pk_change) }

  context 'when allow_pk_change option is false' do
    let(:allow_pk_change) { false }

    context 'with difference' do
      let(:expected_dsl) do
        erbh(<<-ERB)
          create_table "employees", id: :bigint, force: :cascade do |t|
            t.string "name"
          end
        ERB
      end

      it {
        expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-MSG)
[WARNING] Primary key definition of `employees` differ but `allow_pk_change` option is false
  from: {:id=>false}
    to: {:id=>:bigint}
        MSG

        delta = subject.diff(expected_dsl)
        expect(delta.differ?).to be_falsey
        delta.migrate
        expect(subject.dump).to match_ruby actual_dsl
      }
    end

    context 'with no difference' do
      let(:expected_dsl) { actual_dsl }

      it {
        expect(Ridgepole::Logger.instance).to_not receive(:warn)

        delta = subject.diff(expected_dsl)
        expect(delta.differ?).to be_falsey
      }
    end
  end

  context 'when allow_pk_change option is true' do
    let(:allow_pk_change) { true }
    let(:expected_dsl) do
      erbh(<<-ERB)
        create_table "employees", id: :serial, force: :cascade do |t|
          t.string "name"
        end
      ERB
    end

    it {
      delta = subject.diff(expected_dsl)
      expect(delta.differ?).to be_truthy
      delta.migrate
      expect(subject.dump).to match_ruby expected_dsl
    }
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ridgepole-0.8.13 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.9.0.beta spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.12 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.11 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.10 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.9 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.8 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.7 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.6 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.5 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.4 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.3 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.2 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.1 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.0 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.8.0.rc2 spec/postgresql/migrate/migrate_primary_key2_spec.rb
ridgepole-0.7.8 spec/postgresql/migrate/migrate_primary_key2_spec.rb