Sha256: be50fcce544f3980ae436f1c6c0b720b62e8f4f06c5a14584d6d9d2e15100423

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require "spec_helper"

describe Fx::SchemaDumper::Trigger, :db do
  it "dumps a create_trigger for a trigger in the database" do
    connection.execute <<-EOS
      CREATE TABLE users (
          id int PRIMARY KEY,
          name varchar(256),
          upper_name varchar(256)
      );
    EOS
    Fx.database.create_function <<-EOS
      CREATE OR REPLACE FUNCTION uppercase_users_name()
      RETURNS trigger AS $$
      BEGIN
        NEW.upper_name = UPPER(NEW.name);
        RETURN NEW;
      END;
      $$ LANGUAGE plpgsql;
    EOS
    sql_definition = <<-EOS
      CREATE TRIGGER uppercase_users_name
          BEFORE INSERT ON users
          FOR EACH ROW
          EXECUTE FUNCTION uppercase_users_name();
    EOS
    connection.create_trigger(
      :uppercase_users_name,
      sql_definition: sql_definition
    )
    stream = StringIO.new

    ActiveRecord::SchemaDumper.dump(connection, stream)

    output = stream.string
    expect(output).to include "create_trigger :uppercase_users_name"
    expect(output).to include "sql_definition: <<-SQL"
    expect(output).to include "EXECUTE FUNCTION uppercase_users_name()"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fx-0.8.0 spec/fx/schema_dumper/trigger_spec.rb