Sha256: dd4b53e9d21af0520ae5b5f7394be65472f3513467e6f4cf4ff30992ac841ff0

Contents?: true

Size: 1.93 KB

Versions: 12

Compression:

Stored size: 1.93 KB

Contents

# encoding: utf-8

require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
require 'data_objects/spec/result_spec'

describe DataObjects::Postgres::Result do
  behaves_like 'a Result'

  after do
    setup_test_environment
  end

  describe 'without using RETURNING' do

    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 'should respond to #affected_rows' do @result.should.respond_to(:affected_rows) end

    describe 'affected_rows' do

      it 'should return the number of created rows' do
        @result.affected_rows.should == 1
      end

    end

    it 'should respond to #insert_id' do @result.should.respond_to(:insert_id) end

    describe 'insert_id' do

      it 'should return nil' do
        @result.insert_id.should.be.nil
      end

      it 'should be retrievable through curr_val' do
        reader = @connection.create_command("SELECT currval('users_id_seq')").execute_reader
        reader.next!
        reader.values.first.should == 2
      end

    end

  end

  describe 'when using RETURNING' do

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

    after do
      @connection.close
    end

    it 'should respond to #affected_rows' do @result.should.respond_to(:affected_rows) end

    describe 'affected_rows' do

      it 'should return the number of created rows' do
        @result.affected_rows.should == 1
      end

    end

    it 'should respond to #insert_id' do @result.should.respond_to(:insert_id) end

    describe 'insert_id' do

      it 'should return the generated key value' do
        @result.insert_id.should == 2
      end

    end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
do_postgres-0.10.3 spec/result_spec.rb
do_postgres-0.10.3-x86-mswin32-60 spec/result_spec.rb
do_postgres-0.10.3-x86-mingw32 spec/result_spec.rb
do_postgres-0.10.3-java spec/result_spec.rb
do_postgres-0.10.2 spec/result_spec.rb
do_postgres-0.10.2-x86-mswin32-60 spec/result_spec.rb
do_postgres-0.10.2-x86-mingw32 spec/result_spec.rb
do_postgres-0.10.2-java spec/result_spec.rb
do_postgres-0.10.1 spec/result_spec.rb
do_postgres-0.10.1-x86-mswin32-60 spec/result_spec.rb
do_postgres-0.10.1-x86-mingw32 spec/result_spec.rb
do_postgres-0.10.1-java spec/result_spec.rb