Sha256: 094461f7d4f118e87cca297cda9b321abe6ad22ae79862745ca6fd49321eb85e

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

shared_examples 'a Result' do
  before :all do
    setup_test_environment
  end

  before do
    @connection = DataObjects::Connection.new(CONFIG.uri)
    @result = @connection.create_command('INSERT INTO users (name) VALUES (?)').execute_non_query('monkey')
  end

  after do
    @connection.close
  end

  it { expect(@result).to respond_to(:affected_rows) }

  describe 'affected_rows' do
    it 'returns the number of affected rows' do
      expect(@result.affected_rows).to eq 1
    end
  end
end

shared_examples 'a Result which returns inserted key with sequences' do
  describe 'insert_id' do
    before do
      setup_test_environment
      @connection = DataObjects::Connection.new(CONFIG.uri)
      command = @connection.create_command('INSERT INTO users (name) VALUES (?)')
      # execute the command twice and expose the second result
      command.execute_non_query('monkey')
      @result = command.execute_non_query('monkey')
    end

    after do
      @connection.close
    end

    it { expect(@result).to respond_to(:affected_rows) }

    it 'returns the insert_id' do
      # This is actually the 2nd record inserted
      expect(@result.insert_id).to eq 2
    end
  end
end

shared_examples 'a Result which returns nil without sequences' do
  describe 'insert_id' do
    before do
      setup_test_environment
      @connection = DataObjects::Connection.new(CONFIG.uri)
      command = @connection.create_command('INSERT INTO invoices (invoice_number) VALUES (?)')
      # execute the command twice and expose the second result
      @result = command.execute_non_query('monkey')
    end

    after do
      @connection.close
    end

    it 'returns the insert_id' do
      # This is actually the 2nd record inserted
      expect(@result.insert_id).to be_nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sbf-data_objects-0.11.0 lib/data_objects/spec/shared/result_spec.rb
sbf-data_objects-0.10.17 lib/data_objects/spec/shared/result_spec.rb