Sha256: 2ad2d1c3ccac74e65563ed3aacc57719f60e4cdafbc0602ca0a5bd30f4628cc5

Contents?: true

Size: 793 Bytes

Versions: 6

Compression:

Stored size: 793 Bytes

Contents

require 'spec_helper'

module CreateTest
  include DbMod

  def do_thing
    query 'SELECT 1'
  end
end

describe DbMod::Create do
  before do
    @conn = instance_double 'PGconn'
    allow(PGconn).to receive(:connect).and_return(@conn)
  end

  it 'creates module instances' do
    expect(PGconn).to receive(:connect).with(
      nil, 5432, '', '', 'testdb', ENV['USER'], 'trusted?'
    )

    test = CreateTest.create db: 'testdb'

    expect(@conn).to receive(:query).with('SELECT 1')

    test.do_thing
  end

  it 'can be supplied an existing connection' do
    expect(PGconn).not_to receive(:connect)
    expect(@conn).to receive(:is_a?).with(PGconn).and_return true

    test = CreateTest.create @conn

    expect(@conn).to receive(:query).with('SELECT 1')

    test.do_thing
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
db_mod-0.0.6 spec/db_mod/create_spec.rb
db_mod-0.0.5 spec/db_mod/create_spec.rb
db_mod-0.0.4 spec/db_mod/create_spec.rb
db_mod-0.0.3 spec/db_mod/create_spec.rb
db_mod-0.0.2 spec/db_mod/create_spec.rb
db_mod-0.0.1 spec/db_mod/create_spec.rb