Sha256: be25bb05acf053a784ea79d6552bb00542d91cd975ec5cdb737a4571fe43aff1

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

describe ActiveRecord::Migration, "#create_composite_type" do
  before_all { run_migration "create_schema :paint" }

  context "with a full definition" do
    let(:migration) do
      <<~RUBY
        create_composite_type "paint.colored_point" do |t|
          t.column "x", "integer"
          t.column "y", "integer"
          t.column "color", "text", collation: "en_US"
          t.comment "2D point with a color"
        end
      RUBY
    end
    let(:query) { "SELECT (10, -1, 'blue')::paint.colored_point" }

    its(:execution) { is_expected.to enable_sql_request(query) }
    its(:execution) { is_expected.to insert(migration).into_schema }
    its(:inversion) { is_expected.to disable_sql_request(query) }
    its(:inversion) { is_expected.not_to change_schema }
  end

  context "without columns" do
    let(:migration) do
      <<~RUBY
        create_composite_type "paint.nothing" do |t|
          t.comment "2D point with a color"
        end
      RUBY
    end
    let(:query) { "SELECT NULL::paint.nothing" }

    its(:execution) { is_expected.to enable_sql_request(query) }
    its(:execution) { is_expected.to insert(migration).into_schema }
    its(:inversion) { is_expected.to disable_sql_request(query) }
    its(:inversion) { is_expected.not_to change_schema }
  end

  context "without name" do
    let(:migration) do
      <<~RUBY
        create_composite_type do |t|
          t.column "x", "integer"
          t.column "y", "integer"
          t.column "color", "text", collation: "en_US"
          t.comment "2D point with a color"
        end
      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/composite_types/create_composite_type_spec.rb
pg_trunk-0.1.3 spec/operations/composite_types/create_composite_type_spec.rb
pg_trunk-0.1.2 spec/operations/composite_types/create_composite_type_spec.rb
pg_trunk-0.1.1 spec/operations/composite_types/create_composite_type_spec.rb
pg_trunk-0.1.0 spec/operations/composite_types/create_composite_type_spec.rb