Sha256: f900923c3a5753d83c897a3a94993a68176b6d23dd41196e0e0a5ee4c68475fa

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'
require 'sequel'

describe Upsert do
  describe "Plays nice with Sequel" do
    config = ActiveRecord::Base.connection.instance_variable_get(:@config)
    config[:adapter] = case config[:adapter]
                       when 'postgresql' then 'postgres'
                       when 'sqlie3' then 'sqlite'
                       else config[:adapter]
                       end

    let(:db) do
      params = if RUBY_PLATFORM == 'java'
                 RawConnectionFactory::CONFIG
               else
                 config.slice(:adapter, :host, :database, :username, :password).merge(:user => config[:username])
               end
      Sequel.connect(params)
    end

    it "Doesn't explode on connection" do
      expect { db }.to_not raise_error
    end

    it "Doesn't explode when using DB.pool.hold" do
      db.pool.hold do |conn|
        expect {
          upsert = Upsert.new(conn, :pets)
          assert_creates(Pet, [{:name => 'Jerry', :gender => 'male'}]) do
            upsert.row({:name => 'Jerry'}, {:gender => 'male'})
          end
        }.to_not raise_error
      end
    end

    it "Doesn't explode when using DB.synchronize" do
      db.synchronize do |conn|
        expect {
          upsert = Upsert.new(conn, :pets)
          assert_creates(Pet, [{:name => 'Jerry', :gender => 'male'}]) do
            upsert.row({:name => 'Jerry'}, {:gender => 'male'})
          end
        }.to_not raise_error
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
upsert-2.2.1 spec/sequel_spec.rb
upsert-2.2.0 spec/sequel_spec.rb