Sha256: 4b11dcbd9a0c1fcd36565d4c0da5275cad3efd55ce1775f6691921d061f4fd13

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'
require 'stringio'
describe Upsert do
  def fresh_connection
    case ENV['ADAPTER']
    when 'postgresql'
      PGconn.new $conn_config
    when 'mysql2'
      Mysql2::Client.new $conn_config
    end
  end
  describe '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.clear_database_functions(fresh_connection)
        
        # create
        Upsert.new(fresh_connection, :pets).row :name => 'hello'

        # clear
        Upsert.clear_database_functions(fresh_connection)

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

        # no create!
        Upsert.new(fresh_connection, :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 if %w{ postgresql mysql2 }.include?(ENV['ADAPTER'])

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upsert-1.0.2 spec/database_functions_spec.rb