Sha256: 9eba005ca540296dd2b64bfafc9364cb481b9d04a3ef15182b26b477bd84750d

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

require "spec_helper"

module Fx
  module Adapters
    describe Postgres::Triggers, :db do
      describe ".all" do
        it "returns `Trigger` objects" do
          connection = ActiveRecord::Base.connection
          connection.execute <<-EOS.strip_heredoc
            CREATE TABLE users (
                id int PRIMARY KEY,
                name varchar(256),
                upper_name varchar(256)
            );
          EOS
          connection.execute <<-EOS.strip_heredoc
            CREATE OR REPLACE FUNCTION uppercase_users_name()
            RETURNS trigger AS $$
            BEGIN
              NEW.upper_name = UPPER(NEW.name);
              RETURN NEW;
            END;
            $$ LANGUAGE plpgsql;
          EOS
          connection.execute <<-EOS.strip_heredoc
            CREATE TRIGGER uppercase_users_name
                BEFORE INSERT ON users
                FOR EACH ROW
                EXECUTE PROCEDURE uppercase_users_name();
          EOS

          triggers = Postgres::Triggers.new(connection).all

          first = triggers.first
          expect(triggers.size).to eq 1
          expect(first.name).to eq "uppercase_users_name"
          expect(first.definition).to include("BEFORE INSERT")
          expect(first.definition).to match(/ON [public\.users|users]/)
          expect(first.definition).to include("FOR EACH ROW")
          expect(first.definition).to include("EXECUTE PROCEDURE uppercase_users_name()")
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
fx-0.7.0 spec/fx/adapters/postgres/triggers_spec.rb
fx-jets-0.6.3s spec/fx/adapters/postgres/triggers_spec.rb
fx-0.6.2 spec/fx/adapters/postgres/triggers_spec.rb
fx-0.6.1 spec/fx/adapters/postgres/triggers_spec.rb
fx-0.6.0 spec/fx/adapters/postgres/triggers_spec.rb
fx-0.5.0 spec/fx/adapters/postgres/triggers_spec.rb
fx-0.4.0 spec/fx/adapters/postgres/triggers_spec.rb