Sha256: 1cf7c3ff44df4041f7d8ec21ba96c22210944f58f5e1f739b2ea3a218a48c462

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

describe ActiveRecord::Migration, "#rename_enum" do
  before_all { run_migration "create_schema :finances" }
  before { run_migration(old_snippet) }

  let(:old_snippet) do
    <<~RUBY
      create_enum "currency" do |e|
        e.values "CHF", "EUR", "GBP", "USD", "JPY"
        e.comment "Supported currencies"
      end
    RUBY
  end
  let(:old_query) { "SELECT 'USD'::currency;" }

  context "with new name and schema" do
    let(:migration) do
      <<~RUBY
        rename_enum "currency", to: "finances.currency_value"
      RUBY
    end
    let(:new_snippet) do
      <<~RUBY
        create_enum "finances.currency_value" do |e|
          e.values "CHF", "EUR", "GBP", "USD", "JPY"
          e.comment "Supported currencies"
        end
      RUBY
    end
    let(:new_query) { "SELECT 'USD'::finances.currency_value;" }

    its(:execution) { is_expected.to enable_sql_request(new_query) }
    its(:execution) { is_expected.to disable_sql_request(old_query) }
    its(:execution) { is_expected.to remove(old_snippet).from_schema }
    its(:execution) { is_expected.to insert(new_snippet).into_schema }

    its(:inversion) { is_expected.to disable_sql_request(new_query) }
    its(:inversion) { is_expected.to enable_sql_request(old_query) }
    its(:inversion) { is_expected.not_to change_schema }
  end

  context "with the same name and schema" do
    let(:migration) do
      <<~RUBY
        rename_enum "currency", to: "public.currency"
      RUBY
    end

    it { is_expected.to fail_validation.because(/new name must be different/i) }
  end

  context "without new schema/name" do
    let(:migration) do
      <<~RUBY
        rename_enum "currency"
      RUBY
    end

    it { is_expected.to fail_validation.because(/new name can't be blank/i) }
  end

  context "without current name" do
    let(:migration) do
      <<~RUBY
        rename_enum to: "finances.currency_value"
      RUBY
    end

    it { is_expected.to fail_validation.because(/name can't be blank/i) }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_trunk-0.2.0 spec/operations/enums/rename_enum_spec.rb
pg_trunk-0.1.3 spec/operations/enums/rename_enum_spec.rb
pg_trunk-0.1.2 spec/operations/enums/rename_enum_spec.rb
pg_trunk-0.1.1 spec/operations/enums/rename_enum_spec.rb
pg_trunk-0.1.0 spec/operations/enums/rename_enum_spec.rb