Sha256: 54efd881c90e2925cffe221b23ed63d8c1de876e0b1dd165673fe9886f99d8a6

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

require "spec_helper"

describe "Function migrations", :db do
  around do |example|
    sql_definition = <<-EOS
      CREATE OR REPLACE FUNCTION test()
      RETURNS text AS $$
      BEGIN
          RETURN 'test';
      END;
      $$ LANGUAGE plpgsql;
    EOS
    with_function_definition(name: :test, sql_definition: sql_definition) do
      example.run
    end
  end

  it "can run migrations that create functions" do
    migration = Class.new(migration_class) do
      def up
        create_function :test
      end
    end

    expect { run_migration(migration, :up) }.not_to raise_error
  end

  it "can run migrations that drop functions" do
    connection.create_function(:test)

    migration = Class.new(migration_class) do
      def up
        drop_function :test
      end
    end

    expect { run_migration(migration, :up) }.not_to raise_error
  end

  it "can run migrations that updates functions" do
    connection.create_function(:test)

    sql_definition = <<-EOS
      CREATE OR REPLACE FUNCTION test()
      RETURNS text AS $$
      BEGIN
          RETURN 'testest';
      END;
      $$ LANGUAGE plpgsql;
    EOS
    with_function_definition(
      name: :test,
      version: 2,
      sql_definition: sql_definition,
    ) do
      migration = Class.new(migration_class) do
        def change
          update_function :test, version: 2, revert_to_version: 1
        end
      end

      expect { run_migration(migration, :change) }.not_to raise_error
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
fx-0.7.0 spec/features/functions/migrations_spec.rb
fx-jets-0.6.3s spec/features/functions/migrations_spec.rb
fx-0.6.2 spec/features/functions/migrations_spec.rb
fx-0.6.1 spec/features/functions/migrations_spec.rb
fx-0.6.0 spec/features/functions/migrations_spec.rb
fx-0.5.0 spec/features/functions/migrations_spec.rb
fx-0.4.0 spec/features/functions/migrations_spec.rb
fx-0.3.1 spec/features/functions/migrations_spec.rb
fx-0.3.0 spec/features/functions/migrations_spec.rb