Sha256: 3403e593778de167de79d3e1bc2a0cd971bd7eccabe830cf6c5c94c460ce023e

Contents?: true

Size: 1.12 KB

Versions: 9

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 PROCEDURE 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 PROCEDURE uppercase_users_name()"
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
fx-0.7.0 spec/fx/schema_dumper/trigger_spec.rb
fx-jets-0.6.3s spec/fx/schema_dumper/trigger_spec.rb
fx-0.6.2 spec/fx/schema_dumper/trigger_spec.rb
fx-0.6.1 spec/fx/schema_dumper/trigger_spec.rb
fx-0.6.0 spec/fx/schema_dumper/trigger_spec.rb
fx-0.5.0 spec/fx/schema_dumper/trigger_spec.rb
fx-0.4.0 spec/fx/schema_dumper/trigger_spec.rb
fx-0.3.1 spec/fx/schema_dumper/trigger_spec.rb
fx-0.3.0 spec/fx/schema_dumper/trigger_spec.rb