This repository was archived by the owner on Apr 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathresult_spec.rb
86 lines (57 loc) · 1.85 KB
/
result_spec.rb
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
80
81
82
83
84
85
86
# encoding: utf-8
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
require 'data_objects/spec/shared/result_spec'
describe DataObjects::Postgres::Result do
it_should_behave_like 'a Result'
before 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 { @result.should respond_to(:affected_rows) }
describe 'affected_rows' do
it 'should return the number of created rows' do
@result.affected_rows.should == 1
end
end
it { @result.should respond_to(:insert_id) }
describe 'insert_id' do
it 'should return nil' do
@result.insert_id.should be_nil
end
it 'should be retrievable through curr_val' do
# This is actually the 4th record inserted
reader = @connection.create_command("SELECT currval('users_id_seq')").execute_reader
reader.next!
reader.values.first.should == 1
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 { @result.should respond_to(:affected_rows) }
describe 'affected_rows' do
it 'should return the number of created rows' do
@result.affected_rows.should == 1
end
end
it { @result.should respond_to(:insert_id) }
describe 'insert_id' do
it 'should return the generated key value' do
@result.insert_id.should == 1
end
end
end
end