data_objects 0.10.0 → 0.10.1

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 (56) hide show
  1. data/ChangeLog.markdown +20 -0
  2. data/LICENSE +1 -29
  3. data/README.markdown +16 -2
  4. data/Rakefile +41 -7
  5. data/lib/data_objects.rb +3 -2
  6. data/lib/data_objects/byte_array.rb +6 -0
  7. data/lib/data_objects/connection.rb +21 -9
  8. data/lib/data_objects/logger.rb +15 -15
  9. data/lib/data_objects/pooling.rb +250 -0
  10. data/lib/data_objects/reader.rb +16 -0
  11. data/lib/data_objects/spec/bacon.rb +9 -0
  12. data/lib/data_objects/spec/command_spec.rb +54 -47
  13. data/lib/data_objects/spec/connection_spec.rb +119 -30
  14. data/lib/data_objects/spec/encoding_spec.rb +64 -6
  15. data/lib/data_objects/spec/helpers/immediate_red_green_output.rb +59 -0
  16. data/lib/data_objects/spec/helpers/pending.rb +22 -0
  17. data/lib/data_objects/spec/helpers/ssl.rb +21 -0
  18. data/lib/data_objects/spec/reader_spec.rb +47 -24
  19. data/lib/data_objects/spec/result_spec.rb +10 -19
  20. data/lib/data_objects/spec/typecast/array_spec.rb +16 -20
  21. data/lib/data_objects/spec/typecast/bigdecimal_spec.rb +16 -24
  22. data/lib/data_objects/spec/typecast/boolean_spec.rb +16 -24
  23. data/lib/data_objects/spec/typecast/byte_array_spec.rb +11 -15
  24. data/lib/data_objects/spec/typecast/class_spec.rb +7 -11
  25. data/lib/data_objects/spec/typecast/date_spec.rb +17 -25
  26. data/lib/data_objects/spec/typecast/datetime_spec.rb +18 -26
  27. data/lib/data_objects/spec/typecast/float_spec.rb +19 -27
  28. data/lib/data_objects/spec/typecast/integer_spec.rb +10 -14
  29. data/lib/data_objects/spec/typecast/nil_spec.rb +18 -30
  30. data/lib/data_objects/spec/typecast/other_spec.rb +45 -0
  31. data/lib/data_objects/spec/typecast/range_spec.rb +16 -20
  32. data/lib/data_objects/spec/typecast/string_spec.rb +72 -13
  33. data/lib/data_objects/spec/typecast/time_spec.rb +11 -15
  34. data/lib/data_objects/utilities.rb +18 -0
  35. data/lib/data_objects/version.rb +1 -2
  36. data/spec/command_spec.rb +2 -2
  37. data/spec/connection_spec.rb +7 -5
  38. data/spec/do_mock2.rb +31 -0
  39. data/spec/pooling_spec.rb +162 -0
  40. data/spec/reader_spec.rb +7 -4
  41. data/spec/result_spec.rb +2 -2
  42. data/spec/spec_helper.rb +26 -5
  43. data/spec/transaction_spec.rb +11 -9
  44. data/tasks/metrics.rake +36 -0
  45. data/tasks/release.rake +10 -70
  46. data/tasks/spec.rake +16 -14
  47. data/tasks/yard.rake +9 -0
  48. data/tasks/yardstick.rake +19 -0
  49. metadata +53 -27
  50. data/HISTORY.markdown +0 -7
  51. data/Manifest.txt +0 -44
  52. data/spec/lib/pending_helpers.rb +0 -11
  53. data/spec/lib/rspec_immediate_feedback_formatter.rb +0 -53
  54. data/spec/lib/ssl_helpers.rb +0 -20
  55. data/tasks/gem.rake +0 -8
  56. data/tasks/install.rake +0 -13
@@ -1,18 +1,14 @@
1
1
  JRUBY = RUBY_PLATFORM =~ /java/ unless defined?(JRUBY)
2
2
 
3
- share_examples_for 'supporting DateTime' do
3
+ shared 'supporting DateTime' do
4
4
 
5
- include DataObjectsSpecHelpers
5
+ setup_test_environment
6
6
 
7
- before :all do
8
- setup_test_environment
9
- end
10
-
11
- before :each do
7
+ before do
12
8
  @connection = DataObjects::Connection.new(CONFIG.uri)
13
9
  end
14
10
 
15
- after :each do
11
+ after do
16
12
  @connection.close
17
13
  end
18
14
 
@@ -20,7 +16,7 @@ share_examples_for 'supporting DateTime' do
20
16
 
21
17
  describe 'with manual typecasting' do
22
18
 
23
- before do
19
+ before do
24
20
  @command = @connection.create_command("SELECT release_date FROM widgets WHERE ad_description = ?")
25
21
  @command.set_types(DateTime)
26
22
  @reader = @command.execute_reader('Buy this product now!')
@@ -33,7 +29,7 @@ share_examples_for 'supporting DateTime' do
33
29
  end
34
30
 
35
31
  it 'should return the correctly typed result' do
36
- @values.first.should be_kind_of(DateTime)
32
+ @values.first.should.be.kind_of(DateTime)
37
33
  end
38
34
 
39
35
  it 'should return the correct result' do
@@ -45,7 +41,7 @@ share_examples_for 'supporting DateTime' do
45
41
 
46
42
  describe 'with manual typecasting a nil value' do
47
43
 
48
- before do
44
+ before do
49
45
  @command = @connection.create_command("SELECT release_datetime FROM widgets WHERE id = ?")
50
46
  @command.set_types(DateTime)
51
47
  @reader = @command.execute_reader(8)
@@ -58,11 +54,11 @@ share_examples_for 'supporting DateTime' do
58
54
  end
59
55
 
60
56
  it 'should return a nil class' do
61
- @values.first.should be_kind_of(NilClass)
57
+ @values.first.should.be.kind_of(NilClass)
62
58
  end
63
59
 
64
60
  it 'should return nil' do
65
- @values.first.should be_nil
61
+ @values.first.should.be.nil
66
62
  end
67
63
 
68
64
  end
@@ -71,7 +67,7 @@ share_examples_for 'supporting DateTime' do
71
67
 
72
68
  describe 'writing an DateTime' do
73
69
 
74
- before do
70
+ before do
75
71
  local_offset = Rational(Time.local(2008, 2, 14).utc_offset, 86400)
76
72
  @reader = @connection.create_command("SELECT id FROM widgets WHERE release_datetime = ? ORDER BY id").execute_reader(DateTime.civil(2008, 2, 14, 00, 31, 12, local_offset))
77
73
  @reader.next!
@@ -84,26 +80,22 @@ share_examples_for 'supporting DateTime' do
84
80
 
85
81
  it 'should return the correct entry' do
86
82
  #Some of the drivers starts autoincrementation from 0 not 1
87
- @values.first.should satisfy { |val| val == 0 or val == 1 }
83
+ @values.first.should.satisfy { |val| val == 0 or val == 1 }
88
84
  end
89
85
 
90
86
  end
91
87
 
92
88
  end
93
89
 
94
- share_examples_for 'supporting DateTime autocasting' do
90
+ shared 'supporting DateTime autocasting' do
95
91
 
96
- include DataObjectsSpecHelpers
97
-
98
- before :all do
99
- setup_test_environment
100
- end
92
+ setup_test_environment
101
93
 
102
- before :each do
94
+ before do
103
95
  @connection = DataObjects::Connection.new(CONFIG.uri)
104
96
  end
105
97
 
106
- after :each do
98
+ after do
107
99
  @connection.close
108
100
  end
109
101
 
@@ -111,7 +103,7 @@ share_examples_for 'supporting DateTime autocasting' do
111
103
 
112
104
  describe 'with automatic typecasting' do
113
105
 
114
- before do
106
+ before do
115
107
  @reader = @connection.create_command("SELECT release_datetime FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
116
108
  @reader.next!
117
109
  @values = @reader.values
@@ -122,11 +114,11 @@ share_examples_for 'supporting DateTime autocasting' do
122
114
  end
123
115
 
124
116
  it 'should return the correctly typed result' do
125
- @values.first.should be_kind_of(DateTime)
117
+ @values.first.should.be.kind_of(DateTime)
126
118
  end
127
119
 
128
120
  it 'should return the correct result' do
129
- pending "when this is fixed for DST issues"
121
+ pending('when this is fixed for DST issues')
130
122
  @values.first.should == Time.local(2008, 2, 14, 00, 31, 12).to_datetime
131
123
  end
132
124
 
@@ -1,16 +1,12 @@
1
- share_examples_for 'supporting Float' do
1
+ shared 'supporting Float' do
2
2
 
3
- include DataObjectsSpecHelpers
3
+ setup_test_environment
4
4
 
5
- before :all do
6
- setup_test_environment
7
- end
8
-
9
- before :each do
5
+ before do
10
6
  @connection = DataObjects::Connection.new(CONFIG.uri)
11
7
  end
12
8
 
13
- after :each do
9
+ after do
14
10
  @connection.close
15
11
  end
16
12
 
@@ -18,7 +14,7 @@ share_examples_for 'supporting Float' do
18
14
 
19
15
  describe 'with manual typecasting' do
20
16
 
21
- before do
17
+ before do
22
18
  @command = @connection.create_command("SELECT id FROM widgets WHERE ad_description = ?")
23
19
  @command.set_types(Float)
24
20
  @reader = @command.execute_reader('Buy this product now!')
@@ -31,19 +27,19 @@ share_examples_for 'supporting Float' do
31
27
  end
32
28
 
33
29
  it 'should return the correctly typed result' do
34
- @values.first.should be_kind_of(Float)
30
+ @values.first.should.be.kind_of(Float)
35
31
  end
36
32
 
37
33
  it 'should return the correct result' do
38
34
  #Some of the drivers starts autoincrementation from 0 not 1
39
- @values.first.should satisfy { |val| val == 1.0 or val == 0.0 }
35
+ @values.first.should.satisfy { |val| val == 1.0 or val == 0.0 }
40
36
  end
41
37
 
42
38
  end
43
39
 
44
40
  describe 'with manual typecasting a nil' do
45
41
 
46
- before do
42
+ before do
47
43
  @command = @connection.create_command("SELECT cost1 FROM widgets WHERE id = ?")
48
44
  @command.set_types(Float)
49
45
  @reader = @command.execute_reader(5)
@@ -56,11 +52,11 @@ share_examples_for 'supporting Float' do
56
52
  end
57
53
 
58
54
  it 'should return the correctly typed result' do
59
- @values.first.should be_kind_of(NilClass)
55
+ @values.first.should.be.kind_of(NilClass)
60
56
  end
61
57
 
62
58
  it 'should return the correct result' do
63
- @values.first.should be_nil
59
+ @values.first.should.be.nil
64
60
  end
65
61
 
66
62
  end
@@ -68,7 +64,7 @@ share_examples_for 'supporting Float' do
68
64
 
69
65
  describe 'writing an Float' do
70
66
 
71
- before do
67
+ before do
72
68
  @reader = @connection.create_command("SELECT id FROM widgets WHERE id = ?").execute_reader(2.0)
73
69
  @reader.next!
74
70
  @values = @reader.values
@@ -80,26 +76,22 @@ share_examples_for 'supporting Float' do
80
76
 
81
77
  it 'should return the correct entry' do
82
78
  #Some of the drivers starts autoincrementation from 0 not 1
83
- @values.first.should satisfy { |val| val == 1 or val == 2 }
79
+ @values.first.should.satisfy { |val| val == 1 or val == 2 }
84
80
  end
85
81
 
86
82
  end
87
83
 
88
84
  end
89
85
 
90
- share_examples_for 'supporting Float autocasting' do
86
+ shared 'supporting Float autocasting' do
91
87
 
92
- include DataObjectsSpecHelpers
93
-
94
- before :all do
95
- setup_test_environment
96
- end
88
+ setup_test_environment
97
89
 
98
- before :each do
90
+ before do
99
91
  @connection = DataObjects::Connection.new(CONFIG.uri)
100
92
  end
101
93
 
102
- after :each do
94
+ after do
103
95
  @connection.close
104
96
  end
105
97
 
@@ -107,7 +99,7 @@ share_examples_for 'supporting Float autocasting' do
107
99
 
108
100
  describe 'with automatic typecasting' do
109
101
 
110
- before do
102
+ before do
111
103
  @reader = @connection.create_command("SELECT weight, cost1 FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
112
104
  @reader.next!
113
105
  @values = @reader.values
@@ -118,8 +110,8 @@ share_examples_for 'supporting Float autocasting' do
118
110
  end
119
111
 
120
112
  it 'should return the correctly typed result' do
121
- @values.first.should be_kind_of(Float)
122
- @values.last.should be_kind_of(Float)
113
+ @values.first.should.be.kind_of(Float)
114
+ @values.last.should.be.kind_of(Float)
123
115
  end
124
116
 
125
117
  it 'should return the correct result' do
@@ -1,16 +1,12 @@
1
- share_examples_for 'supporting Integer' do
1
+ shared 'supporting Integer' do
2
2
 
3
- include DataObjectsSpecHelpers
3
+ setup_test_environment
4
4
 
5
- before :all do
6
- setup_test_environment
7
- end
8
-
9
- before :each do
5
+ before do
10
6
  @connection = DataObjects::Connection.new(CONFIG.uri)
11
7
  end
12
8
 
13
- after :each do
9
+ after do
14
10
  @connection.close
15
11
  end
16
12
 
@@ -18,7 +14,7 @@ share_examples_for 'supporting Integer' do
18
14
 
19
15
  describe 'with automatic typecasting' do
20
16
 
21
- before do
17
+ before do
22
18
  @reader = @connection.create_command("SELECT id FROM widgets WHERE ad_description = ?").execute_reader('Buy this product now!')
23
19
  @reader.next!
24
20
  @values = @reader.values
@@ -29,19 +25,19 @@ share_examples_for 'supporting Integer' do
29
25
  end
30
26
 
31
27
  it 'should return the correctly typed result' do
32
- @values.first.should be_kind_of(Integer)
28
+ @values.first.should.be.kind_of(Integer)
33
29
  end
34
30
 
35
31
  it 'should return the correct result' do
36
32
  #Some of the drivers starts autoincrementation from 0 not 1
37
- @values.first.should satisfy { |val| val == 1 or val == 0 }
33
+ @values.first.should.satisfy { |val| val == 1 or val == 0 }
38
34
  end
39
35
 
40
36
  end
41
37
 
42
38
  describe 'with manual typecasting' do
43
39
 
44
- before do
40
+ before do
45
41
  @command = @connection.create_command("SELECT weight FROM widgets WHERE ad_description = ?")
46
42
  @command.set_types(Integer)
47
43
  @reader = @command.execute_reader('Buy this product now!')
@@ -54,7 +50,7 @@ share_examples_for 'supporting Integer' do
54
50
  end
55
51
 
56
52
  it 'should return the correctly typed result' do
57
- @values.first.should be_kind_of(Integer)
53
+ @values.first.should.be.kind_of(Integer)
58
54
  end
59
55
 
60
56
  it 'should return the correct result' do
@@ -67,7 +63,7 @@ share_examples_for 'supporting Integer' do
67
63
 
68
64
  describe 'writing an Integer' do
69
65
 
70
- before do
66
+ before do
71
67
  @reader = @connection.create_command("SELECT id FROM widgets WHERE id = ?").execute_reader(2)
72
68
  @reader.next!
73
69
  @values = @reader.values
@@ -1,16 +1,12 @@
1
- share_examples_for 'supporting Nil' do
1
+ shared 'supporting Nil' do
2
2
 
3
- include DataObjectsSpecHelpers
3
+ setup_test_environment
4
4
 
5
- before :all do
6
- setup_test_environment
7
- end
8
-
9
- before :each do
5
+ before do
10
6
  @connection = DataObjects::Connection.new(CONFIG.uri)
11
7
  end
12
8
 
13
- after :each do
9
+ after do
14
10
  @connection.close
15
11
  end
16
12
 
@@ -18,7 +14,7 @@ share_examples_for 'supporting Nil' do
18
14
 
19
15
  describe 'with manual typecasting' do
20
16
 
21
- before do
17
+ before do
22
18
  @command = @connection.create_command("SELECT flags FROM widgets WHERE ad_description = ?")
23
19
  @command.set_types(NilClass)
24
20
  @reader = @command.execute_reader('Buy this product now!')
@@ -31,7 +27,7 @@ share_examples_for 'supporting Nil' do
31
27
  end
32
28
 
33
29
  it 'should return the correctly typed result' do
34
- @values.first.should be_kind_of(NilClass)
30
+ @values.first.should.be.kind_of(NilClass)
35
31
  end
36
32
 
37
33
  it 'should return the correct result' do
@@ -44,19 +40,15 @@ share_examples_for 'supporting Nil' do
44
40
 
45
41
  end
46
42
 
47
- share_examples_for 'supporting writing an Nil' do
48
-
49
- include DataObjectsSpecHelpers
43
+ shared 'supporting writing an Nil' do
50
44
 
51
- before :all do
52
- setup_test_environment
53
- end
45
+ setup_test_environment
54
46
 
55
- before :each do
47
+ before do
56
48
  @connection = DataObjects::Connection.new(CONFIG.uri)
57
49
  end
58
50
 
59
- after :each do
51
+ after do
60
52
  @connection.close
61
53
  end
62
54
 
@@ -68,7 +60,7 @@ share_examples_for 'supporting writing an Nil' do
68
60
 
69
61
  describe 'as a parameter' do
70
62
 
71
- before do
63
+ before do
72
64
  @reader = @connection.create_command("SELECT id FROM widgets WHERE ad_description IN (?) ORDER BY id").execute_reader(nil)
73
65
  end
74
66
 
@@ -77,7 +69,7 @@ share_examples_for 'supporting writing an Nil' do
77
69
  end
78
70
 
79
71
  it 'should return the correct entry' do
80
- @reader.next!.should be_false
72
+ @reader.next!.should.be.false
81
73
  end
82
74
 
83
75
  end
@@ -86,19 +78,15 @@ share_examples_for 'supporting writing an Nil' do
86
78
 
87
79
  end
88
80
 
89
- share_examples_for 'supporting Nil autocasting' do
90
-
91
- include DataObjectsSpecHelpers
81
+ shared 'supporting Nil autocasting' do
92
82
 
93
- before :all do
94
- setup_test_environment
95
- end
83
+ setup_test_environment
96
84
 
97
- before :each do
85
+ before do
98
86
  @connection = DataObjects::Connection.new(CONFIG.uri)
99
87
  end
100
88
 
101
- after :each do
89
+ after do
102
90
  @connection.close
103
91
  end
104
92
 
@@ -106,7 +94,7 @@ share_examples_for 'supporting Nil autocasting' do
106
94
 
107
95
  describe 'with automatic typecasting' do
108
96
 
109
- before do
97
+ before do
110
98
  @reader = @connection.create_command("SELECT ad_description FROM widgets WHERE id = ?").execute_reader(3)
111
99
  @reader.next!
112
100
  @values = @reader.values
@@ -117,7 +105,7 @@ share_examples_for 'supporting Nil autocasting' do
117
105
  end
118
106
 
119
107
  it 'should return the correctly typed result' do
120
- @values.first.should be_kind_of(NilClass)
108
+ @values.first.should.be.kind_of(NilClass)
121
109
  end
122
110
 
123
111
  it 'should return the correct result' do
@@ -0,0 +1,45 @@
1
+ class ::CustomTextType
2
+
3
+ def initialize(value)
4
+ @value = value
5
+ end
6
+
7
+ def to_s
8
+ @value.to_s
9
+ end
10
+
11
+ end
12
+
13
+ shared 'supporting other (unknown) type' do
14
+
15
+ setup_test_environment
16
+
17
+ before do
18
+ @connection = DataObjects::Connection.new(CONFIG.uri)
19
+ end
20
+
21
+ after do
22
+ @connection.close
23
+ end
24
+
25
+ describe 'writing an object of unknown type' do
26
+
27
+ before do
28
+ @command = @connection.create_command("SELECT whitepaper_text FROM widgets WHERE whitepaper_text = ?")
29
+ @command.set_types(::CustomTextType)
30
+ @reader = @command.execute_reader('String')
31
+ @reader.next!
32
+ @values = @reader.values
33
+ end
34
+
35
+ after do
36
+ @reader.close
37
+ end
38
+
39
+ it 'should return the correct entry' do
40
+ @values.first.should == 'String'
41
+ end
42
+
43
+ end
44
+
45
+ end