Sha256: 9dc20342c347c5130d950a5390efa6d5160473d412e9b37665fa9811ac1a24c9

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'
require 'stringio'
describe Upsert do
  if ENV['ADAPTER'] == 'postgresql'
    describe 'PostgreSQL database functions' do
      it "re-uses merge functions across connections" do
        begin
          io = StringIO.new
          old_logger = Upsert.logger
          Upsert.logger = Logger.new io, Logger::INFO

          # clear
          Upsert.new(PGconn.new(:dbname => 'upsert_test'), :pets).buffer.clear_database_functions
          
          # create
          Upsert.new(PGconn.new(:dbname => 'upsert_test'), :pets).row :name => 'hello'

          # clear
          Upsert.new(PGconn.new(:dbname => 'upsert_test'), :pets).buffer.clear_database_functions

          # create (#2)
          Upsert.new(PGconn.new(:dbname => 'upsert_test'), :pets).row :name => 'hello'

          # no create!
          Upsert.new(PGconn.new(:dbname => 'upsert_test'), :pets).row :name => 'hello'
          
          io.rewind
          hits = io.read.split("\n").grep(/Creating or replacing/)
          hits.length.should == 2
        ensure
          Upsert.logger = old_logger
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upsert-0.4.0 spec/database_functions_spec.rb