File: result_spec.rb

package info (click to toggle)
libdataobjects-ruby 0.10.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 336 kB
  • ctags: 200
  • sloc: ruby: 2,729; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 1,884 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
shared 'a Result' do

  setup_test_environment

  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 affected rows' do
      @result.affected_rows.should == 1
    end

  end

end

shared 'a Result which returns inserted key with sequences' 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 'should respond to #affected_rows' do @result.should.respond_to(:affected_rows) end

  describe 'insert_id' do

    it 'should return the insert_id' do
      # This is actually the 2nd record inserted
      @result.insert_id.should == 2
    end

  end

end

shared 'a Result which returns nil without sequences' 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 'should respond to #affected_rows' do @result.should.respond_to(:affected_rows) end

  describe 'insert_id' do

    it 'should return the insert_id' do
      # This is actually the 2nd record inserted
      @result.insert_id.should.be.nil
    end

  end

end