data_objects 0.9.11 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +19 -1
- data/Rakefile +6 -80
- data/lib/data_objects.rb +1 -6
- data/lib/data_objects/command.rb +51 -1
- data/lib/data_objects/connection.rb +13 -2
- data/lib/data_objects/logger.rb +40 -32
- data/lib/data_objects/quoting.rb +28 -32
- data/lib/data_objects/reader.rb +6 -5
- data/lib/data_objects/result.rb +7 -1
- data/lib/data_objects/spec/command_spec.rb +191 -0
- data/lib/data_objects/spec/connection_spec.rb +106 -0
- data/lib/data_objects/spec/encoding_spec.rb +31 -0
- data/lib/data_objects/spec/quoting_spec.rb +0 -0
- data/lib/data_objects/spec/reader_spec.rb +156 -0
- data/lib/data_objects/spec/result_spec.rb +58 -0
- data/lib/data_objects/spec/typecast/array_spec.rb +36 -0
- data/lib/data_objects/spec/typecast/bigdecimal_spec.rb +107 -0
- data/lib/data_objects/spec/typecast/boolean_spec.rb +107 -0
- data/lib/data_objects/spec/typecast/byte_array_spec.rb +86 -0
- data/lib/data_objects/spec/typecast/class_spec.rb +63 -0
- data/lib/data_objects/spec/typecast/date_spec.rb +108 -0
- data/lib/data_objects/spec/typecast/datetime_spec.rb +110 -0
- data/lib/data_objects/spec/typecast/float_spec.rb +111 -0
- data/lib/data_objects/spec/typecast/integer_spec.rb +86 -0
- data/lib/data_objects/spec/typecast/ipaddr_spec.rb +0 -0
- data/lib/data_objects/spec/typecast/nil_spec.rb +116 -0
- data/lib/data_objects/spec/typecast/range_spec.rb +36 -0
- data/lib/data_objects/spec/typecast/string_spec.rb +86 -0
- data/lib/data_objects/spec/typecast/time_spec.rb +64 -0
- data/lib/data_objects/transaction.rb +20 -13
- data/lib/data_objects/uri.rb +24 -2
- data/lib/data_objects/version.rb +2 -1
- data/spec/command_spec.rb +1 -17
- data/spec/connection_spec.rb +1 -23
- data/spec/lib/pending_helpers.rb +11 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
- data/spec/result_spec.rb +0 -3
- data/tasks/gem.rake +49 -0
- data/tasks/install.rake +13 -0
- data/tasks/release.rake +74 -0
- data/tasks/spec.rake +18 -0
- metadata +51 -30
- data/.gitignore +0 -2
- data/spec/dataobjects_spec.rb +0 -1
- data/spec/spec.opts +0 -2
@@ -0,0 +1,58 @@
|
|
1
|
+
share_examples_for 'a Result' do
|
2
|
+
|
3
|
+
include DataObjectsSpecHelpers
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
setup_test_environment
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
11
|
+
@result = @connection.create_command("INSERT INTO users (name) VALUES (?)").execute_non_query("monkey")
|
12
|
+
end
|
13
|
+
|
14
|
+
after :each do
|
15
|
+
@connection.close
|
16
|
+
end
|
17
|
+
|
18
|
+
it { @result.should respond_to(:affected_rows) }
|
19
|
+
|
20
|
+
describe 'affected_rows' do
|
21
|
+
|
22
|
+
it 'should return the number of affected rows' do
|
23
|
+
@result.affected_rows.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
share_examples_for 'a Result which returns inserted keys' do
|
31
|
+
|
32
|
+
include DataObjectsSpecHelpers
|
33
|
+
|
34
|
+
before :all do
|
35
|
+
setup_test_environment
|
36
|
+
end
|
37
|
+
|
38
|
+
before :each do
|
39
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
40
|
+
@result = @connection.create_command("INSERT INTO users (name) VALUES (?)").execute_non_query("monkey")
|
41
|
+
end
|
42
|
+
|
43
|
+
after :each do
|
44
|
+
@connection.close
|
45
|
+
end
|
46
|
+
|
47
|
+
it { @result.should respond_to(:affected_rows) }
|
48
|
+
|
49
|
+
describe 'insert_id' do
|
50
|
+
|
51
|
+
it 'should return the number of affected rows' do
|
52
|
+
# This is actually the 2nd record inserted
|
53
|
+
@result.insert_id.should == 2
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
share_examples_for 'supporting Array' do
|
2
|
+
|
3
|
+
include DataObjectsSpecHelpers
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
setup_test_environment
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
@connection.close
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'passing an Array as a parameter in execute_reader' do
|
18
|
+
|
19
|
+
before do
|
20
|
+
@reader = @connection.create_command("SELECT * FROM widgets WHERE id in ?").execute_reader([2,3,4,5])
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
@reader.close
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return correct number of rows' do
|
28
|
+
counter = 0
|
29
|
+
while(@reader.next!) do
|
30
|
+
counter += 1
|
31
|
+
end
|
32
|
+
counter.should == 4
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
share_examples_for 'supporting BigDecimal' do
|
2
|
+
|
3
|
+
include DataObjectsSpecHelpers
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
setup_test_environment
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
@connection.close
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'reading a BigDecimal' do
|
18
|
+
|
19
|
+
describe 'with manual typecasting' do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@command = @connection.create_command("SELECT cost1 FROM widgets WHERE ad_description = ?")
|
23
|
+
@command.set_types(BigDecimal)
|
24
|
+
@reader = @command.execute_reader('Buy this product now!')
|
25
|
+
@reader.next!
|
26
|
+
@values = @reader.values
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
@reader.close
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return the correctly typed result' do
|
34
|
+
@values.first.should be_kind_of(BigDecimal)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return the correct result' do
|
38
|
+
@values.first.should == 10.23
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'writing an Integer' do
|
46
|
+
|
47
|
+
before do
|
48
|
+
@reader = @connection.create_command("SELECT id FROM widgets WHERE id = ?").execute_reader(BigDecimal("2.0"))
|
49
|
+
@reader.next!
|
50
|
+
@values = @reader.values
|
51
|
+
end
|
52
|
+
|
53
|
+
after do
|
54
|
+
@reader.close
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should return the correct entry' do
|
58
|
+
@values.first.should == 2
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
share_examples_for 'supporting BigDecimal autocasting' do
|
66
|
+
|
67
|
+
include DataObjectsSpecHelpers
|
68
|
+
|
69
|
+
before :all do
|
70
|
+
setup_test_environment
|
71
|
+
end
|
72
|
+
|
73
|
+
before :each do
|
74
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
75
|
+
end
|
76
|
+
|
77
|
+
after :each do
|
78
|
+
@connection.close
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'reading a BigDecimal' do
|
82
|
+
|
83
|
+
describe 'with automatic typecasting' do
|
84
|
+
|
85
|
+
before do
|
86
|
+
@reader = @connection.create_command("SELECT cost2 FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
|
87
|
+
@reader.next!
|
88
|
+
@values = @reader.values
|
89
|
+
end
|
90
|
+
|
91
|
+
after do
|
92
|
+
@reader.close
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should return the correctly typed result' do
|
96
|
+
@values.first.should be_kind_of(BigDecimal)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should return the correct result' do
|
100
|
+
@values.first.should == 50.23
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
share_examples_for 'supporting Boolean' do
|
2
|
+
|
3
|
+
include DataObjectsSpecHelpers
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
setup_test_environment
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
@connection.close
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'reading a Boolean' do
|
18
|
+
|
19
|
+
describe 'with manual typecasting' do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@command = @connection.create_command("SELECT flags FROM widgets WHERE ad_description = ?")
|
23
|
+
@command.set_types(TrueClass)
|
24
|
+
@reader = @command.execute_reader('Buy this product now!')
|
25
|
+
@reader.next!
|
26
|
+
@values = @reader.values
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
@reader.close
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return the correctly typed result' do
|
34
|
+
@values.first.should be_kind_of(FalseClass)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return the correct result' do
|
38
|
+
@values.first.should == false
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'writing an Boolean' do
|
46
|
+
|
47
|
+
before do
|
48
|
+
@reader = @connection.create_command("SELECT id FROM widgets WHERE flags = ?").execute_reader(true)
|
49
|
+
@reader.next!
|
50
|
+
@values = @reader.values
|
51
|
+
end
|
52
|
+
|
53
|
+
after do
|
54
|
+
@reader.close
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should return the correct entry' do
|
58
|
+
@values.first.should == 2
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
share_examples_for 'supporting Boolean autocasting' do
|
66
|
+
|
67
|
+
include DataObjectsSpecHelpers
|
68
|
+
|
69
|
+
before :all do
|
70
|
+
setup_test_environment
|
71
|
+
end
|
72
|
+
|
73
|
+
before :each do
|
74
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
75
|
+
end
|
76
|
+
|
77
|
+
after :each do
|
78
|
+
@connection.close
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'reading a Boolean' do
|
82
|
+
|
83
|
+
describe 'with automatic typecasting' do
|
84
|
+
|
85
|
+
before do
|
86
|
+
@reader = @connection.create_command("SELECT flags FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
|
87
|
+
@reader.next!
|
88
|
+
@values = @reader.values
|
89
|
+
end
|
90
|
+
|
91
|
+
after do
|
92
|
+
@reader.close
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should return the correctly typed result' do
|
96
|
+
@values.first.should be_kind_of(FalseClass)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should return the correct result' do
|
100
|
+
@values.first.should == false
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
share_examples_for 'supporting ByteArray' do
|
2
|
+
|
3
|
+
include DataObjectsSpecHelpers
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
setup_test_environment
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
@connection.close
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'reading a ByteArray' do
|
18
|
+
|
19
|
+
describe 'with automatic typecasting' do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@reader = @connection.create_command("SELECT cad_drawing FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
|
23
|
+
@reader.next!
|
24
|
+
@values = @reader.values
|
25
|
+
end
|
26
|
+
|
27
|
+
after do
|
28
|
+
@reader.close
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should return the correctly typed result' do
|
32
|
+
@values.first.should be_kind_of(::Extlib::ByteArray)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return the correct result' do
|
36
|
+
@values.first.should == "CAD \001 \000 DRAWING"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'with manual typecasting' do
|
42
|
+
|
43
|
+
before do
|
44
|
+
@command = @connection.create_command("SELECT cad_drawing FROM widgets WHERE ad_description = ?")
|
45
|
+
@command.set_types(::Extlib::ByteArray)
|
46
|
+
@reader = @command.execute_reader('Buy this product now!')
|
47
|
+
@reader.next!
|
48
|
+
@values = @reader.values
|
49
|
+
end
|
50
|
+
|
51
|
+
after do
|
52
|
+
@reader.close
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should return the correctly typed result' do
|
56
|
+
@values.first.should be_kind_of(::Extlib::ByteArray)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should return the correct result' do
|
60
|
+
@values.first.should == "CAD \001 \000 DRAWING"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'writing a ByteArray' do
|
68
|
+
|
69
|
+
before do
|
70
|
+
@reader = @connection.create_command("SELECT id FROM widgets WHERE id = ?").execute_reader(::Extlib::ByteArray.new("2"))
|
71
|
+
@reader.next!
|
72
|
+
@values = @reader.values
|
73
|
+
end
|
74
|
+
|
75
|
+
after do
|
76
|
+
@reader.close
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should return the correct entry' do
|
80
|
+
#Some of the drivers starts autoincrementation from 0 not 1
|
81
|
+
@values.first.should satisfy { |val| val == 2 or val == 1 }
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
share_examples_for 'supporting Class' do
|
2
|
+
|
3
|
+
include DataObjectsSpecHelpers
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
setup_test_environment
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
@connection.close
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'reading a Class' do
|
18
|
+
|
19
|
+
describe 'with manual typecasting' do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@command = @connection.create_command("SELECT whitepaper_text FROM widgets WHERE ad_description = ?")
|
23
|
+
@command.set_types(Class)
|
24
|
+
@reader = @command.execute_reader('Buy this product now!')
|
25
|
+
@reader.next!
|
26
|
+
@values = @reader.values
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
@reader.close
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return the correctly typed result' do
|
34
|
+
@values.first.should be_kind_of(Class)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return the correct result' do
|
38
|
+
@values.first.should == String
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'writing a Class' do
|
46
|
+
|
47
|
+
before do
|
48
|
+
@reader = @connection.create_command("SELECT whitepaper_text FROM widgets WHERE whitepaper_text = ?").execute_reader(String)
|
49
|
+
@reader.next!
|
50
|
+
@values = @reader.values
|
51
|
+
end
|
52
|
+
|
53
|
+
after do
|
54
|
+
@reader.close
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should return the correct entry' do
|
58
|
+
@values.first.should == "String"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|