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.
- data/ChangeLog.markdown +20 -0
- data/LICENSE +1 -29
- data/README.markdown +16 -2
- data/Rakefile +41 -7
- data/lib/data_objects.rb +3 -2
- data/lib/data_objects/byte_array.rb +6 -0
- data/lib/data_objects/connection.rb +21 -9
- data/lib/data_objects/logger.rb +15 -15
- data/lib/data_objects/pooling.rb +250 -0
- data/lib/data_objects/reader.rb +16 -0
- data/lib/data_objects/spec/bacon.rb +9 -0
- data/lib/data_objects/spec/command_spec.rb +54 -47
- data/lib/data_objects/spec/connection_spec.rb +119 -30
- data/lib/data_objects/spec/encoding_spec.rb +64 -6
- data/lib/data_objects/spec/helpers/immediate_red_green_output.rb +59 -0
- data/lib/data_objects/spec/helpers/pending.rb +22 -0
- data/lib/data_objects/spec/helpers/ssl.rb +21 -0
- data/lib/data_objects/spec/reader_spec.rb +47 -24
- data/lib/data_objects/spec/result_spec.rb +10 -19
- data/lib/data_objects/spec/typecast/array_spec.rb +16 -20
- data/lib/data_objects/spec/typecast/bigdecimal_spec.rb +16 -24
- data/lib/data_objects/spec/typecast/boolean_spec.rb +16 -24
- data/lib/data_objects/spec/typecast/byte_array_spec.rb +11 -15
- data/lib/data_objects/spec/typecast/class_spec.rb +7 -11
- data/lib/data_objects/spec/typecast/date_spec.rb +17 -25
- data/lib/data_objects/spec/typecast/datetime_spec.rb +18 -26
- data/lib/data_objects/spec/typecast/float_spec.rb +19 -27
- data/lib/data_objects/spec/typecast/integer_spec.rb +10 -14
- data/lib/data_objects/spec/typecast/nil_spec.rb +18 -30
- data/lib/data_objects/spec/typecast/other_spec.rb +45 -0
- data/lib/data_objects/spec/typecast/range_spec.rb +16 -20
- data/lib/data_objects/spec/typecast/string_spec.rb +72 -13
- data/lib/data_objects/spec/typecast/time_spec.rb +11 -15
- data/lib/data_objects/utilities.rb +18 -0
- data/lib/data_objects/version.rb +1 -2
- data/spec/command_spec.rb +2 -2
- data/spec/connection_spec.rb +7 -5
- data/spec/do_mock2.rb +31 -0
- data/spec/pooling_spec.rb +162 -0
- data/spec/reader_spec.rb +7 -4
- data/spec/result_spec.rb +2 -2
- data/spec/spec_helper.rb +26 -5
- data/spec/transaction_spec.rb +11 -9
- data/tasks/metrics.rake +36 -0
- data/tasks/release.rake +10 -70
- data/tasks/spec.rake +16 -14
- data/tasks/yard.rake +9 -0
- data/tasks/yardstick.rake +19 -0
- metadata +53 -27
- data/HISTORY.markdown +0 -7
- data/Manifest.txt +0 -44
- data/spec/lib/pending_helpers.rb +0 -11
- data/spec/lib/rspec_immediate_feedback_formatter.rb +0 -53
- data/spec/lib/ssl_helpers.rb +0 -20
- data/tasks/gem.rake +0 -8
- data/tasks/install.rake +0 -13
data/lib/data_objects/reader.rb
CHANGED
@@ -2,6 +2,8 @@ module DataObjects
|
|
2
2
|
# Abstract class to read rows from a query result
|
3
3
|
class Reader
|
4
4
|
|
5
|
+
include Enumerable
|
6
|
+
|
5
7
|
# Return the array of field names
|
6
8
|
def fields
|
7
9
|
raise NotImplementedError.new
|
@@ -27,5 +29,19 @@ module DataObjects
|
|
27
29
|
raise NotImplementedError.new
|
28
30
|
end
|
29
31
|
|
32
|
+
# Yield each row to the given block as a Hash
|
33
|
+
def each
|
34
|
+
begin
|
35
|
+
while next!
|
36
|
+
row = {}
|
37
|
+
fields.each_with_index { |field, index| row[field] = values[index] }
|
38
|
+
yield row
|
39
|
+
end
|
40
|
+
ensure
|
41
|
+
close
|
42
|
+
end
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
30
46
|
end
|
31
47
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#
|
2
|
+
# Standard Bacon configuration for DataObjects spec suite
|
3
|
+
#
|
4
|
+
require 'bacon'
|
5
|
+
require 'data_objects/spec/helpers/immediate_red_green_output'
|
6
|
+
require 'data_objects/spec/helpers/pending'
|
7
|
+
|
8
|
+
Bacon.extend Bacon::ImmediateRedGreenOutput
|
9
|
+
Bacon.summary_on_exit
|
@@ -1,45 +1,43 @@
|
|
1
|
-
WINDOWS = Gem.win_platform?
|
1
|
+
WINDOWS = Gem.win_platform? || (JRUBY && ENV_JAVA['os.name'] =~ /windows/i)
|
2
2
|
|
3
|
-
|
3
|
+
shared 'a Command' do
|
4
4
|
|
5
|
-
|
5
|
+
setup_test_environment
|
6
6
|
|
7
|
-
before
|
8
|
-
setup_test_environment
|
9
|
-
end
|
10
|
-
|
11
|
-
before :each do
|
7
|
+
before do
|
12
8
|
@connection = DataObjects::Connection.new(CONFIG.uri)
|
13
9
|
@command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
|
14
10
|
@reader = @connection.create_command("SELECT code, name FROM widgets WHERE ad_description = ?")
|
15
11
|
end
|
16
12
|
|
17
|
-
after
|
13
|
+
after do
|
18
14
|
@connection.close
|
19
15
|
end
|
20
16
|
|
21
|
-
it
|
17
|
+
it 'should be a kind of Command' do @command.should.be.kind_of(DataObjects::Command) end
|
22
18
|
|
23
|
-
it
|
19
|
+
it 'should respond to #execute_non_query' do @command.should.respond_to(:execute_non_query) end
|
24
20
|
|
25
21
|
describe 'execute_non_query' do
|
26
22
|
|
27
23
|
describe 'with an invalid statement' do
|
28
24
|
|
29
|
-
before
|
25
|
+
before do
|
30
26
|
@invalid_command = @connection.create_command("INSERT INTO non_existent_table (tester) VALUES (1)")
|
31
27
|
end
|
32
28
|
|
33
29
|
it 'should raise an error on an invalid query' do
|
34
|
-
|
30
|
+
should.raise(DataObjects::SQLError) { @invalid_command.execute_non_query }
|
35
31
|
end
|
36
32
|
|
37
33
|
it 'should raise an error with too few binding parameters' do
|
38
|
-
lambda { @command.execute_non_query("Too", "Many") }.should
|
34
|
+
lambda { @command.execute_non_query("Too", "Many") }.should.raise(ArgumentError).
|
35
|
+
message.should.match(/Binding mismatch: 2 for 1/)
|
39
36
|
end
|
40
37
|
|
41
38
|
it 'should raise an error with too many binding parameters' do
|
42
|
-
lambda { @command.execute_non_query }.should
|
39
|
+
lambda { @command.execute_non_query }.should.raise(ArgumentError).
|
40
|
+
message.should.match(/Binding mismatch: 0 for 1/)
|
43
41
|
end
|
44
42
|
|
45
43
|
end
|
@@ -47,45 +45,48 @@ share_examples_for 'a Command' do
|
|
47
45
|
describe 'with a valid statement' do
|
48
46
|
|
49
47
|
it 'should not raise an error with an explicit nil as parameter' do
|
50
|
-
|
48
|
+
should.not.raise(ArgumentError) { @command.execute_non_query(nil) }
|
51
49
|
end
|
52
50
|
|
53
51
|
end
|
54
52
|
|
55
53
|
describe 'with a valid statement and ? inside quotes' do
|
56
54
|
|
57
|
-
before
|
55
|
+
before do
|
58
56
|
@command_with_quotes = @connection.create_command("INSERT INTO users (name) VALUES ('will it work? ')")
|
59
57
|
end
|
60
58
|
|
61
59
|
it 'should not raise an error' do
|
62
|
-
|
60
|
+
should.not.raise(ArgumentError) { @command_with_quotes.execute_non_query }
|
63
61
|
end
|
64
62
|
|
65
63
|
end
|
66
64
|
|
67
65
|
end
|
68
66
|
|
69
|
-
it
|
67
|
+
it 'should respond to #execute_reader' do @command.should.respond_to(:execute_reader) end
|
70
68
|
|
71
69
|
describe 'execute_reader' do
|
72
70
|
|
73
71
|
describe 'with an invalid reader' do
|
74
72
|
|
75
|
-
before
|
73
|
+
before do
|
76
74
|
@invalid_reader = @connection.create_command("SELECT * FROM non_existent_widgets WHERE ad_description = ?")
|
77
75
|
end
|
78
76
|
|
79
77
|
it 'should raise an error on an invalid query' do
|
80
|
-
|
78
|
+
# FIXME JRuby (and MRI): Should this be an ArgumentError or DataObjects::SQLError?
|
79
|
+
should.raise(ArgumentError, DataObjects::SQLError) { @invalid_reader.execute_reader }
|
81
80
|
end
|
82
81
|
|
83
82
|
it 'should raise an error with too few binding parameters' do
|
84
|
-
lambda { @reader.execute_reader("Too", "Many") }.should
|
83
|
+
lambda { @reader.execute_reader("Too", "Many") }.should.raise(ArgumentError).
|
84
|
+
message.should.match(/Binding mismatch: 2 for 1/)
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'should raise an error with too many binding parameters' do
|
88
|
-
lambda { @reader.execute_reader }.should
|
88
|
+
lambda { @reader.execute_reader }.should.raise(ArgumentError).
|
89
|
+
message.should.match(/Binding mismatch: 0 for 1/)
|
89
90
|
end
|
90
91
|
|
91
92
|
end
|
@@ -93,19 +94,19 @@ share_examples_for 'a Command' do
|
|
93
94
|
describe 'with a valid reader' do
|
94
95
|
|
95
96
|
it 'should not raise an error with an explicit nil as parameter' do
|
96
|
-
|
97
|
+
should.not.raise(ArgumentError) { @reader.execute_reader(nil) }
|
97
98
|
end
|
98
99
|
|
99
100
|
end
|
100
101
|
|
101
102
|
describe 'with a valid reader and ? inside column alias' do
|
102
103
|
|
103
|
-
before
|
104
|
+
before do
|
104
105
|
@reader_with_quotes = @connection.create_command("SELECT code AS \"code?\", name FROM widgets WHERE ad_description = ?")
|
105
106
|
end
|
106
107
|
|
107
108
|
it 'should not raise an error' do
|
108
|
-
|
109
|
+
should.not.raise(ArgumentError) { @reader_with_quotes.execute_reader(nil) }
|
109
110
|
end
|
110
111
|
|
111
112
|
end
|
@@ -113,18 +114,18 @@ share_examples_for 'a Command' do
|
|
113
114
|
|
114
115
|
end
|
115
116
|
|
116
|
-
it
|
117
|
+
it 'should respond to #set_types' do @command.should.respond_to(:set_types) end
|
117
118
|
|
118
119
|
describe 'set_types' do
|
119
120
|
|
120
121
|
describe 'is invalid when used with a statement' do
|
121
122
|
|
122
|
-
before
|
123
|
+
before do
|
123
124
|
@command.set_types(String)
|
124
125
|
end
|
125
126
|
|
126
127
|
it 'should raise an error when types are set' do
|
127
|
-
|
128
|
+
should.raise(ArgumentError) { @command.execute_non_query }
|
128
129
|
end
|
129
130
|
|
130
131
|
end
|
@@ -133,12 +134,14 @@ share_examples_for 'a Command' do
|
|
133
134
|
|
134
135
|
it 'should raise an error with too few types' do
|
135
136
|
@reader.set_types(String)
|
136
|
-
lambda { @reader.execute_reader("One parameter") }.should
|
137
|
+
lambda { @reader.execute_reader("One parameter") }.should.raise(ArgumentError).
|
138
|
+
message.should.match(/Field-count mismatch. Expected 1 fields, but the query yielded 2/)
|
137
139
|
end
|
138
140
|
|
139
141
|
it 'should raise an error with too many types' do
|
140
142
|
@reader.set_types(String, String, BigDecimal)
|
141
|
-
lambda { @reader.execute_reader("One parameter") }.should
|
143
|
+
lambda { @reader.execute_reader("One parameter") }.should.raise(ArgumentError).
|
144
|
+
message.should.match(/Field-count mismatch. Expected 3 fields, but the query yielded 2/)
|
142
145
|
end
|
143
146
|
|
144
147
|
end
|
@@ -147,25 +150,33 @@ share_examples_for 'a Command' do
|
|
147
150
|
|
148
151
|
it 'should not raise an error with correct number of types' do
|
149
152
|
@reader.set_types(String, String)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
+
should.not.raise(ArgumentError) { @result = @reader.execute_reader('Buy this product now!') }
|
154
|
+
should.not.raise(DataObjects::SQLError) { @result.next! }
|
155
|
+
should.not.raise(DataObjects::DataError) { @result.values }
|
153
156
|
@result.close
|
154
157
|
end
|
155
158
|
|
156
159
|
it 'should also support old style array argument types' do
|
157
160
|
@reader.set_types([String, String])
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
+
should.not.raise(ArgumentError) { @result = @reader.execute_reader('Buy this product now!') }
|
162
|
+
should.not.raise(DataObjects::DataError) { @result.next! }
|
163
|
+
should.not.raise(DataObjects::DataError) { @result.values }
|
161
164
|
@result.close
|
162
165
|
end
|
163
166
|
|
167
|
+
it 'should allow subtype types' do
|
168
|
+
class MyString < String; end
|
169
|
+
@reader.set_types(MyString, String)
|
170
|
+
should.not.raise(ArgumentError) { @result = @reader.execute_reader('Buy this product now!') }
|
171
|
+
should.not.raise(DataObjects::DataError) { @result.next! }
|
172
|
+
should.not.raise(DataObjects::DataError) { @result.values }
|
173
|
+
@result.close
|
174
|
+
end
|
164
175
|
end
|
165
176
|
|
166
177
|
end
|
167
178
|
|
168
|
-
it
|
179
|
+
it 'should respond to #to_s' do @command.should.respond_to(:to_s) end
|
169
180
|
|
170
181
|
describe 'to_s' do
|
171
182
|
|
@@ -174,17 +185,13 @@ share_examples_for 'a Command' do
|
|
174
185
|
|
175
186
|
end
|
176
187
|
|
177
|
-
|
178
|
-
|
179
|
-
include DataObjectsSpecHelpers
|
188
|
+
shared 'a Command with async' do
|
180
189
|
|
181
|
-
|
182
|
-
setup_test_environment
|
183
|
-
end
|
190
|
+
setup_test_environment
|
184
191
|
|
185
192
|
describe 'running queries in parallel' do
|
186
193
|
|
187
|
-
before
|
194
|
+
before do
|
188
195
|
|
189
196
|
threads = []
|
190
197
|
|
@@ -208,12 +215,12 @@ share_examples_for 'a Command with async' do
|
|
208
215
|
@finish = Time.now
|
209
216
|
end
|
210
217
|
|
211
|
-
after
|
218
|
+
after do
|
212
219
|
@connection.close
|
213
220
|
end
|
214
221
|
|
215
222
|
it "should finish within 2 seconds" do
|
216
|
-
pending_if("Ruby on Windows doesn't support
|
223
|
+
pending_if("Ruby on Windows doesn't support asynchronous operations", WINDOWS) do
|
217
224
|
(@finish - @start).should < 2
|
218
225
|
end
|
219
226
|
end
|
@@ -1,27 +1,24 @@
|
|
1
|
-
|
1
|
+
shared 'a Connection' do
|
2
2
|
|
3
|
-
|
3
|
+
setup_test_environment
|
4
4
|
|
5
|
-
before
|
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
|
9
|
+
after do
|
14
10
|
@connection.close
|
15
11
|
end
|
16
12
|
|
17
|
-
it
|
18
|
-
it
|
13
|
+
it 'should be a kind of Connection' do @connection.should.be.kind_of(::DataObjects::Connection) end
|
14
|
+
it 'should be a kind of Pooling' do @connection.should.be.kind_of(::DataObjects::Pooling) end
|
19
15
|
|
20
|
-
it
|
16
|
+
it 'should respond to #dispose' do @connection.should.respond_to(:dispose) end
|
21
17
|
|
22
18
|
describe 'dispose' do
|
23
19
|
|
24
20
|
describe 'on open connection' do
|
21
|
+
|
25
22
|
before do
|
26
23
|
@open_connection = DataObjects::Connection.new("#{@driver}://#{@user}:#{@password}@#{@host}:#{@port}#{@database}")
|
27
24
|
@open_connection.detach
|
@@ -31,10 +28,14 @@ share_examples_for 'a Connection' do
|
|
31
28
|
@open_connection.close
|
32
29
|
end
|
33
30
|
|
34
|
-
it
|
31
|
+
it 'dispose should be true' do
|
32
|
+
@open_connection.dispose.should.be.true
|
33
|
+
end
|
34
|
+
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'on closed connection' do
|
38
|
+
|
38
39
|
before do
|
39
40
|
@closed_connection = DataObjects::Connection.new("#{@driver}://#{@user}:#{@password}@#{@host}:#{@port}#{@database}")
|
40
41
|
@closed_connection.detach
|
@@ -45,73 +46,124 @@ share_examples_for 'a Connection' do
|
|
45
46
|
@closed_connection.close
|
46
47
|
end
|
47
48
|
|
48
|
-
it
|
49
|
+
it 'dispose should be false' do
|
50
|
+
@closed_connection.dispose.should.be.false
|
51
|
+
end
|
49
52
|
|
50
53
|
it 'should raise an error on creating a command' do
|
51
|
-
|
54
|
+
should.raise(DataObjects::ConnectionError) {
|
55
|
+
@closed_connection.create_command("INSERT INTO non_existent_table (tester) VALUES (1)").execute_non_query
|
56
|
+
}
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
55
60
|
end
|
56
61
|
|
57
|
-
it
|
62
|
+
it 'should respond to #create_command' do @connection.should.respond_to(:create_command) end
|
58
63
|
|
59
64
|
describe 'create_command' do
|
60
|
-
it
|
65
|
+
it 'should be a kind of Command' do
|
66
|
+
@connection.create_command('This is a dummy command').should.be.kind_of(DataObjects::Command)
|
67
|
+
end
|
61
68
|
end
|
62
69
|
|
63
|
-
|
70
|
+
describe 'various connection URIs' do
|
71
|
+
|
72
|
+
def test_connection(conn)
|
73
|
+
reader = conn.create_command(CONFIG.testsql || "SELECT 1").execute_reader
|
74
|
+
reader.next!
|
75
|
+
reader.values[0]
|
76
|
+
end
|
64
77
|
|
65
|
-
|
78
|
+
after do
|
79
|
+
@open_connection.close if @open_connection
|
80
|
+
end
|
66
81
|
|
67
|
-
|
68
|
-
|
69
|
-
|
82
|
+
it 'should open with an uri object' do
|
83
|
+
uri = DataObjects::URI.new(
|
84
|
+
@driver,
|
85
|
+
@user,
|
86
|
+
@password,
|
87
|
+
@host,
|
88
|
+
@port.to_i,
|
89
|
+
@database,
|
90
|
+
nil, nil
|
91
|
+
)
|
92
|
+
test_connection(DataObjects::Connection.new(uri)).should == 1
|
70
93
|
end
|
71
94
|
|
95
|
+
it 'should work with non-JDBC URLs' do
|
96
|
+
conn = DataObjects::Connection.new("#{CONFIG.uri.sub(/jdbc:/, '')}")
|
97
|
+
test_connection(conn).should == 1
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
shared 'a Connection with authentication support' do
|
104
|
+
|
105
|
+
%w[ @driver @user @password @host @port @database ].each do |ivar|
|
106
|
+
raise "+#{ivar}+ should be defined in before block" unless instance_variable_get(ivar)
|
72
107
|
end
|
73
108
|
|
74
109
|
describe 'with an invalid URI' do
|
75
110
|
|
111
|
+
# FIXME JRuby (and MRI): Should these be ArgumentError or DataObjects::SQLError?
|
112
|
+
|
76
113
|
def connecting_with(uri)
|
77
114
|
lambda { DataObjects::Connection.new(uri) }
|
78
115
|
end
|
79
116
|
|
80
117
|
it 'should raise an error if no database specified' do
|
81
|
-
connecting_with("#{@driver}://#{@user}:#{@password}@#{@host}:#{@port}").should
|
118
|
+
connecting_with("#{@driver}://#{@user}:#{@password}@#{@host}:#{@port}").should.raise(ArgumentError, DataObjects::Error)
|
82
119
|
end
|
83
120
|
|
84
121
|
it 'should raise an error if bad username is given' do
|
85
|
-
connecting_with("#{@driver}://thisreallyshouldntexist:#{@password}@#{@host}:#{@port}#{@database}").should
|
122
|
+
connecting_with("#{@driver}://thisreallyshouldntexist:#{@password}@#{@host}:#{@port}#{@database}").should.raise(ArgumentError, DataObjects::Error)
|
86
123
|
end
|
87
124
|
|
88
125
|
it 'should raise an error if bad password is given' do
|
89
|
-
connecting_with("#{@driver}://#{@user}:completelyincorrectpassword:#{@host}:#{@port}#{@database}").should
|
126
|
+
connecting_with("#{@driver}://#{@user}:completelyincorrectpassword:#{@host}:#{@port}#{@database}").should.raise(ArgumentError, DataObjects::Error)
|
90
127
|
end
|
91
128
|
|
92
129
|
it 'should raise an error if an invalid port is given' do
|
93
|
-
connecting_with("#{@driver}://#{@user}:#{@password}:#{@host}:648646543#{@database}").should
|
130
|
+
connecting_with("#{@driver}://#{@user}:#{@password}:#{@host}:648646543#{@database}").should.raise(ArgumentError, DataObjects::Error)
|
94
131
|
end
|
95
132
|
|
96
133
|
it 'should raise an error if an invalid database is given' do
|
97
|
-
connecting_with("#{@driver}://#{@user}:#{@password}:#{@host}:#{@port}/someweirddatabase").should
|
134
|
+
connecting_with("#{@driver}://#{@user}:#{@password}:#{@host}:#{@port}/someweirddatabase").should.raise(ArgumentError, DataObjects::Error)
|
98
135
|
end
|
99
136
|
|
100
137
|
it 'should raise an error with a meaningless URI' do
|
101
|
-
connecting_with("#{@driver}://peekaboo$2!@#4543").should
|
138
|
+
connecting_with("#{@driver}://peekaboo$2!@#4543").should.raise(Addressable::URI::InvalidURIError)
|
102
139
|
end
|
103
140
|
|
104
141
|
end
|
105
142
|
|
106
143
|
end
|
107
144
|
|
108
|
-
|
145
|
+
shared 'a Connection with JDBC URL support' do
|
146
|
+
|
147
|
+
def test_connection(conn)
|
148
|
+
reader = conn.create_command(CONFIG.testsql || "SELECT 1").execute_reader
|
149
|
+
reader.next!
|
150
|
+
reader.values[0]
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should work with JDBC URLs' do
|
154
|
+
conn = DataObjects::Connection.new(CONFIG.jdbc_uri || "jdbc:#{CONFIG.uri.sub(/jdbc:/, '')}")
|
155
|
+
test_connection(conn).should == 1
|
156
|
+
end
|
157
|
+
|
158
|
+
end if JRUBY
|
159
|
+
|
160
|
+
shared 'a Connection with SSL support' do
|
109
161
|
|
110
162
|
if DataObjectsSpecHelpers.test_environment_supports_ssl?
|
111
163
|
describe 'connecting with SSL' do
|
112
164
|
|
113
165
|
it 'should connect securely' do
|
114
|
-
DataObjects::Connection.new("#{CONFIG.uri}?#{CONFIG.ssl}").secure?.should
|
166
|
+
DataObjects::Connection.new("#{CONFIG.uri}?#{CONFIG.ssl}").secure?.should.be.true
|
115
167
|
end
|
116
168
|
|
117
169
|
end
|
@@ -120,9 +172,46 @@ share_examples_for 'a Connection with SSL support' do
|
|
120
172
|
describe 'connecting without SSL' do
|
121
173
|
|
122
174
|
it 'should not connect securely' do
|
123
|
-
DataObjects::Connection.new(CONFIG.uri).secure?.should
|
175
|
+
DataObjects::Connection.new(CONFIG.uri).secure?.should.be.false
|
124
176
|
end
|
125
177
|
|
126
178
|
end
|
127
179
|
|
128
180
|
end
|
181
|
+
|
182
|
+
shared 'a Connection via JDNI' do
|
183
|
+
|
184
|
+
if JRUBY
|
185
|
+
describe 'connecting with JNDI' do
|
186
|
+
|
187
|
+
before do
|
188
|
+
begin
|
189
|
+
@jndi = Java::data_objects.JNDITestSetup.new("jdbc:#{CONFIG.uri}".gsub(/:sqlite3:/, ':sqlite:'), CONFIG.jdbc_driver, 'mydb')
|
190
|
+
@jndi.setup()
|
191
|
+
rescue
|
192
|
+
puts "use (after installation of maven) to test JNDI:"
|
193
|
+
puts "mvn rails:spec -Drails.fork=false"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
after do
|
198
|
+
@jndi.teardown() unless @jndi.nil?
|
199
|
+
end
|
200
|
+
|
201
|
+
unless @jndi.nil?
|
202
|
+
it 'should connect' do
|
203
|
+
begin
|
204
|
+
c = DataObjects::Connection.new("java:comp/env/jdbc/mydb?scheme=#{CONFIG.scheme}")
|
205
|
+
c.should_not be_nil
|
206
|
+
rescue => e
|
207
|
+
if e.message =~ /java.naming.factory.initial/
|
208
|
+
puts "use (after installation of maven) to test JNDI:"
|
209
|
+
puts "mvn rails:spec -Drails.fork=false"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|