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.
Files changed (45) hide show
  1. data/Manifest.txt +19 -1
  2. data/Rakefile +6 -80
  3. data/lib/data_objects.rb +1 -6
  4. data/lib/data_objects/command.rb +51 -1
  5. data/lib/data_objects/connection.rb +13 -2
  6. data/lib/data_objects/logger.rb +40 -32
  7. data/lib/data_objects/quoting.rb +28 -32
  8. data/lib/data_objects/reader.rb +6 -5
  9. data/lib/data_objects/result.rb +7 -1
  10. data/lib/data_objects/spec/command_spec.rb +191 -0
  11. data/lib/data_objects/spec/connection_spec.rb +106 -0
  12. data/lib/data_objects/spec/encoding_spec.rb +31 -0
  13. data/lib/data_objects/spec/quoting_spec.rb +0 -0
  14. data/lib/data_objects/spec/reader_spec.rb +156 -0
  15. data/lib/data_objects/spec/result_spec.rb +58 -0
  16. data/lib/data_objects/spec/typecast/array_spec.rb +36 -0
  17. data/lib/data_objects/spec/typecast/bigdecimal_spec.rb +107 -0
  18. data/lib/data_objects/spec/typecast/boolean_spec.rb +107 -0
  19. data/lib/data_objects/spec/typecast/byte_array_spec.rb +86 -0
  20. data/lib/data_objects/spec/typecast/class_spec.rb +63 -0
  21. data/lib/data_objects/spec/typecast/date_spec.rb +108 -0
  22. data/lib/data_objects/spec/typecast/datetime_spec.rb +110 -0
  23. data/lib/data_objects/spec/typecast/float_spec.rb +111 -0
  24. data/lib/data_objects/spec/typecast/integer_spec.rb +86 -0
  25. data/lib/data_objects/spec/typecast/ipaddr_spec.rb +0 -0
  26. data/lib/data_objects/spec/typecast/nil_spec.rb +116 -0
  27. data/lib/data_objects/spec/typecast/range_spec.rb +36 -0
  28. data/lib/data_objects/spec/typecast/string_spec.rb +86 -0
  29. data/lib/data_objects/spec/typecast/time_spec.rb +64 -0
  30. data/lib/data_objects/transaction.rb +20 -13
  31. data/lib/data_objects/uri.rb +24 -2
  32. data/lib/data_objects/version.rb +2 -1
  33. data/spec/command_spec.rb +1 -17
  34. data/spec/connection_spec.rb +1 -23
  35. data/spec/lib/pending_helpers.rb +11 -0
  36. data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
  37. data/spec/result_spec.rb +0 -3
  38. data/tasks/gem.rake +49 -0
  39. data/tasks/install.rake +13 -0
  40. data/tasks/release.rake +74 -0
  41. data/tasks/spec.rake +18 -0
  42. metadata +51 -30
  43. data/.gitignore +0 -2
  44. data/spec/dataobjects_spec.rb +0 -1
  45. data/spec/spec.opts +0 -2
@@ -0,0 +1,108 @@
1
+ share_examples_for 'supporting Date' 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 Date' do
18
+
19
+ describe 'with manual typecasting' do
20
+
21
+ before do
22
+ @command = @connection.create_command("SELECT release_datetime FROM widgets WHERE ad_description = ?")
23
+ @command.set_types(Date)
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(Date)
35
+ end
36
+
37
+ it 'should return the correct result' do
38
+ @values.first.should == Date.civil(2008, 2, 14)
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ describe 'writing an Date' do
46
+
47
+ before do
48
+ @reader = @connection.create_command("SELECT id FROM widgets WHERE release_date = ?").execute_reader(Date.civil(2008, 2, 14))
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
+ #Some of the drivers starts autoincrementation from 0 not 1
59
+ @values.first.should satisfy { |val| val == 1 or val == 0 }
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ share_examples_for 'supporting Date autocasting' do
67
+
68
+ include DataObjectsSpecHelpers
69
+
70
+ before :all do
71
+ setup_test_environment
72
+ end
73
+
74
+ before :each do
75
+ @connection = DataObjects::Connection.new(CONFIG.uri)
76
+ end
77
+
78
+ after :each do
79
+ @connection.close
80
+ end
81
+
82
+ describe 'reading a Date' do
83
+
84
+ describe 'with automatic typecasting' do
85
+
86
+ before do
87
+ @reader = @connection.create_command("SELECT release_date FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
88
+ @reader.next!
89
+ @values = @reader.values
90
+ end
91
+
92
+ after do
93
+ @reader.close
94
+ end
95
+
96
+ it 'should return the correctly typed result' do
97
+ @values.first.should be_kind_of(Date)
98
+ end
99
+
100
+ it 'should return the correct result' do
101
+ @values.first.should == Date.civil(2008, 2, 14)
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,110 @@
1
+ share_examples_for 'supporting DateTime' 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 DateTime' do
18
+
19
+ describe 'with manual typecasting' do
20
+
21
+ before do
22
+ @command = @connection.create_command("SELECT release_date FROM widgets WHERE ad_description = ?")
23
+ @command.set_types(DateTime)
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(DateTime)
35
+ end
36
+
37
+ it 'should return the correct result' do
38
+ date = @values.first
39
+ Date.civil(date.year, date.mon, date.day).should == Date.civil(2008, 2, 14)
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe 'writing an DateTime' do
47
+
48
+ before do
49
+ @reader = @connection.create_command("SELECT id FROM widgets WHERE release_datetime = ?").execute_reader(DateTime.civil(2008, 2, 14, 00, 31, 12, 0))
50
+ @reader.next!
51
+ @values = @reader.values
52
+ end
53
+
54
+ after do
55
+ @reader.close
56
+ end
57
+
58
+ it 'should return the correct entry' do
59
+ #Some of the drivers starts autoincrementation from 0 not 1
60
+ @values.first.should satisfy { |val| val == 0 or val == 1 }
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ share_examples_for 'supporting DateTime autocasting' do
68
+
69
+ include DataObjectsSpecHelpers
70
+
71
+ before :all do
72
+ setup_test_environment
73
+ end
74
+
75
+ before :each do
76
+ @connection = DataObjects::Connection.new(CONFIG.uri)
77
+ end
78
+
79
+ after :each do
80
+ @connection.close
81
+ end
82
+
83
+ describe 'reading a DateTime' do
84
+
85
+ describe 'with automatic typecasting' do
86
+
87
+ before do
88
+ @reader = @connection.create_command("SELECT release_datetime FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
89
+ @reader.next!
90
+ @values = @reader.values
91
+ end
92
+
93
+ after do
94
+ @reader.close
95
+ end
96
+
97
+ it 'should return the correctly typed result' do
98
+ @values.first.should be_kind_of(DateTime)
99
+ end
100
+
101
+ it 'should return the correct result' do
102
+ pending "when this is fixed for DST issues"
103
+ @values.first.should == Time.local(2008, 2, 14, 00, 31, 12).to_datetime
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,111 @@
1
+ share_examples_for 'supporting Float' 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 Float' do
18
+
19
+ describe 'with manual typecasting' do
20
+
21
+ before do
22
+ @command = @connection.create_command("SELECT id FROM widgets WHERE ad_description = ?")
23
+ @command.set_types(Float)
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(Float)
35
+ end
36
+
37
+ it 'should return the correct result' do
38
+ #Some of the drivers starts autoincrementation from 0 not 1
39
+ @values.first.should satisfy { |val| val == 1.0 or val == 0.0 }
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe 'writing an Float' do
47
+
48
+ before do
49
+ @reader = @connection.create_command("SELECT id FROM widgets WHERE id = ?").execute_reader(2.0)
50
+ @reader.next!
51
+ @values = @reader.values
52
+ end
53
+
54
+ after do
55
+ @reader.close
56
+ end
57
+
58
+ it 'should return the correct entry' do
59
+ #Some of the drivers starts autoincrementation from 0 not 1
60
+ @values.first.should satisfy { |val| val == 1 or val == 2 }
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ share_examples_for 'supporting Float autocasting' do
68
+
69
+ include DataObjectsSpecHelpers
70
+
71
+ before :all do
72
+ setup_test_environment
73
+ end
74
+
75
+ before :each do
76
+ @connection = DataObjects::Connection.new(CONFIG.uri)
77
+ end
78
+
79
+ after :each do
80
+ @connection.close
81
+ end
82
+
83
+ describe 'reading a Float' do
84
+
85
+ describe 'with automatic typecasting' do
86
+
87
+ before do
88
+ @reader = @connection.create_command("SELECT weight, cost1 FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
89
+ @reader.next!
90
+ @values = @reader.values
91
+ end
92
+
93
+ after do
94
+ @reader.close
95
+ end
96
+
97
+ it 'should return the correctly typed result' do
98
+ @values.first.should be_kind_of(Float)
99
+ @values.last.should be_kind_of(Float)
100
+ end
101
+
102
+ it 'should return the correct result' do
103
+ @values.first.should == 13.4
104
+ @values.last.should == 10.23
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,86 @@
1
+ share_examples_for 'supporting Integer' 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 an Integer' do
18
+
19
+ describe 'with automatic typecasting' do
20
+
21
+ before do
22
+ @reader = @connection.create_command("SELECT id 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(Integer)
33
+ end
34
+
35
+ it 'should return the correct result' do
36
+ #Some of the drivers starts autoincrementation from 0 not 1
37
+ @values.first.should satisfy { |val| val == 1 or val == 0 }
38
+ end
39
+
40
+ end
41
+
42
+ describe 'with manual typecasting' do
43
+
44
+ before do
45
+ @command = @connection.create_command("SELECT weight FROM widgets WHERE ad_description = ?")
46
+ @command.set_types(Integer)
47
+ @reader = @command.execute_reader('Buy this product now!')
48
+ @reader.next!
49
+ @values = @reader.values
50
+ end
51
+
52
+ after do
53
+ @reader.close
54
+ end
55
+
56
+ it 'should return the correctly typed result' do
57
+ @values.first.should be_kind_of(Integer)
58
+ end
59
+
60
+ it 'should return the correct result' do
61
+ @values.first.should == 13
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+
68
+ describe 'writing an Integer' do
69
+
70
+ before do
71
+ @reader = @connection.create_command("SELECT id FROM widgets WHERE id = ?").execute_reader(2)
72
+ @reader.next!
73
+ @values = @reader.values
74
+ end
75
+
76
+ after do
77
+ @reader.close
78
+ end
79
+
80
+ it 'should return the correct entry' do
81
+ @values.first.should == 2
82
+ end
83
+
84
+ end
85
+
86
+ end
File without changes
@@ -0,0 +1,116 @@
1
+ share_examples_for 'supporting Nil' 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 Nil' 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(NilClass)
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(NilClass)
35
+ end
36
+
37
+ it 'should return the correct result' do
38
+ @values.first.should == nil
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ share_examples_for 'supporting writing an Nil' do
48
+
49
+ describe 'supporting writing an Nil' do
50
+
51
+ describe 'as a parameter' do
52
+
53
+ before do
54
+ @reader = @connection.create_command("SELECT id FROM widgets WHERE ad_description IS ?").execute_reader(nil)
55
+ @reader.next!
56
+ @values = @reader.values
57
+ end
58
+
59
+ after do
60
+ @reader.close
61
+ end
62
+
63
+ it 'should return the correct entry' do
64
+ #Some of the drivers starts autoincrementation from 0 not 1
65
+ @values.first.should satisfy { |val| val == 3 or val == 2 }
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ share_examples_for 'supporting Nil autocasting' do
75
+
76
+ include DataObjectsSpecHelpers
77
+
78
+ before :all do
79
+ setup_test_environment
80
+ end
81
+
82
+ before :each do
83
+ @connection = DataObjects::Connection.new(CONFIG.uri)
84
+ end
85
+
86
+ after :each do
87
+ @connection.close
88
+ end
89
+
90
+ describe 'reading a Nil' do
91
+
92
+ describe 'with automatic typecasting' do
93
+
94
+ before do
95
+ @reader = @connection.create_command("SELECT ad_description FROM widgets WHERE id = ?").execute_reader(3)
96
+ @reader.next!
97
+ @values = @reader.values
98
+ end
99
+
100
+ after do
101
+ @reader.close
102
+ end
103
+
104
+ it 'should return the correctly typed result' do
105
+ @values.first.should be_kind_of(NilClass)
106
+ end
107
+
108
+ it 'should return the correct result' do
109
+ @values.first.should == nil
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
116
+ end