data_objects 0.10.3 → 0.10.4.rc1

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 (50) hide show
  1. data/LICENSE +1 -1
  2. data/README.markdown +1 -1
  3. data/Rakefile +6 -32
  4. data/lib/data_objects/connection.rb +9 -6
  5. data/lib/data_objects/pooling.rb +1 -1
  6. data/lib/data_objects/spec/lib/pending_helpers.rb +11 -0
  7. data/lib/data_objects/spec/{helpers → lib}/ssl.rb +0 -0
  8. data/lib/data_objects/spec/setup.rb +5 -0
  9. data/lib/data_objects/spec/{command_spec.rb → shared/command_spec.rb} +54 -50
  10. data/lib/data_objects/spec/shared/connection_spec.rb +245 -0
  11. data/lib/data_objects/spec/{encoding_spec.rb → shared/encoding_spec.rb} +41 -43
  12. data/lib/data_objects/spec/shared/error/sql_error_spec.rb +30 -0
  13. data/lib/data_objects/spec/{quoting_spec.rb → shared/quoting_spec.rb} +0 -0
  14. data/lib/data_objects/spec/{reader_spec.rb → shared/reader_spec.rb} +31 -26
  15. data/lib/data_objects/spec/shared/result_spec.rb +79 -0
  16. data/lib/data_objects/spec/{typecast → shared/typecast}/array_spec.rb +4 -2
  17. data/lib/data_objects/spec/{typecast → shared/typecast}/bigdecimal_spec.rb +12 -8
  18. data/lib/data_objects/spec/{typecast → shared/typecast}/boolean_spec.rb +14 -10
  19. data/lib/data_objects/spec/{typecast → shared/typecast}/byte_array_spec.rb +6 -4
  20. data/lib/data_objects/spec/{typecast → shared/typecast}/class_spec.rb +5 -3
  21. data/lib/data_objects/spec/{typecast → shared/typecast}/date_spec.rb +13 -9
  22. data/lib/data_objects/spec/{typecast → shared/typecast}/datetime_spec.rb +14 -11
  23. data/lib/data_objects/spec/{typecast → shared/typecast}/float_spec.rb +17 -13
  24. data/lib/data_objects/spec/{typecast → shared/typecast}/integer_spec.rb +7 -5
  25. data/lib/data_objects/spec/{typecast → shared/typecast}/ipaddr_spec.rb +0 -0
  26. data/lib/data_objects/spec/{typecast → shared/typecast}/nil_spec.rb +23 -17
  27. data/lib/data_objects/spec/{typecast → shared/typecast}/other_spec.rb +11 -9
  28. data/lib/data_objects/spec/{typecast → shared/typecast}/range_spec.rb +4 -2
  29. data/lib/data_objects/spec/{typecast → shared/typecast}/string_spec.rb +10 -8
  30. data/lib/data_objects/spec/{typecast → shared/typecast}/time_spec.rb +44 -6
  31. data/lib/data_objects/transaction.rb +9 -0
  32. data/lib/data_objects/uri.rb +62 -4
  33. data/lib/data_objects/version.rb +1 -1
  34. data/spec/command_spec.rb +2 -2
  35. data/spec/connection_spec.rb +45 -25
  36. data/spec/pooling_spec.rb +9 -9
  37. data/spec/reader_spec.rb +11 -12
  38. data/spec/result_spec.rb +13 -11
  39. data/spec/spec_helper.rb +1 -16
  40. data/spec/transaction_spec.rb +9 -11
  41. data/spec/uri_spec.rb +35 -27
  42. data/tasks/spec.rake +8 -17
  43. metadata +40 -56
  44. data/lib/data_objects/spec/bacon.rb +0 -9
  45. data/lib/data_objects/spec/connection_spec.rb +0 -217
  46. data/lib/data_objects/spec/error/sql_error_spec.rb +0 -19
  47. data/lib/data_objects/spec/helpers/immediate_red_green_output.rb +0 -59
  48. data/lib/data_objects/spec/helpers/pending.rb +0 -22
  49. data/lib/data_objects/spec/result_spec.rb +0 -79
  50. data/tasks/metrics.rake +0 -36
data/spec/reader_spec.rb CHANGED
@@ -1,23 +1,22 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
3
  describe DataObjects::Reader do
4
+ subject { command.execute_reader }
4
5
 
5
- it "should define a standard API" do
6
- connection = DataObjects::Connection.new('mock://localhost')
6
+ let(:connection) { DataObjects::Connection.new('mock://localhost') }
7
+ let(:command) { connection.create_command('SELECT * FROM example') }
7
8
 
8
- command = connection.create_command("SELECT * FROM example")
9
+ after { connection.close }
9
10
 
10
- reader = command.execute_reader
11
+ context 'should define a standard API' do
11
12
 
12
- reader.should.be.kind_of(Enumerable)
13
+ it { should be_a(Enumerable) }
13
14
 
14
- reader.should.respond_to(:close)
15
- reader.should.respond_to(:next!)
16
- reader.should.respond_to(:values)
17
- reader.should.respond_to(:fields)
18
- reader.should.respond_to(:each)
19
-
20
- connection.close
15
+ it { should respond_to(:close) }
16
+ it { should respond_to(:next!) }
17
+ it { should respond_to(:values) }
18
+ it { should respond_to(:fields) }
19
+ it { should respond_to(:each) }
21
20
  end
22
21
 
23
22
  end
data/spec/result_spec.rb CHANGED
@@ -1,21 +1,23 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
3
  describe DataObjects::Result do
4
+ subject { command.execute_non_query }
4
5
 
5
- it "should define a standard API" do
6
- connection = DataObjects::Connection.new('mock://localhost')
6
+ let(:connection) { DataObjects::Connection.new('mock://localhost') }
7
+ let(:command) { connection.create_command('SELECT * FROM example') }
7
8
 
8
- command = connection.create_command("SELECT * FROM example")
9
+ after { connection.close }
9
10
 
10
- result = command.execute_non_query
11
+ context 'should define a standard API' do
11
12
 
12
- # Affected Rows:
13
- result.should.respond_to(:to_i)
14
- result.to_i.should == 0
13
+ it 'should provide the number of affected rows' do
14
+ should respond_to(:to_i)
15
+ subject.to_i.should == 0
16
+ end
15
17
 
16
- # The id of the inserted row.
17
- result.should.respond_to(:insert_id)
18
- connection.close
19
- end
18
+ it 'should provide the id of the inserted row' do
19
+ should respond_to(:insert_id)
20
+ end
20
21
 
22
+ end
21
23
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'data_objects'
3
- require 'data_objects/spec/bacon'
4
- require 'mocha/api'
5
- require 'mocha/object'
6
- require 'win32console' if RUBY_PLATFORM =~ /mingw|mswin/
3
+ require 'rspec'
7
4
 
8
5
  module DataObjects::Pooling
9
6
  class << self
@@ -14,17 +11,5 @@ module DataObjects::Pooling
14
11
  end
15
12
  end
16
13
 
17
- # see http://gnufied.org/2008/06/12/making-ruby-bacon-play-with-mocha/
18
- class Bacon::Context
19
- include Mocha::API
20
- alias_method :old_it,:it
21
- def it description,&block
22
- mocha_setup
23
- old_it(description,&block)
24
- mocha_verify
25
- mocha_teardown
26
- end
27
- end
28
-
29
14
  require File.expand_path(File.join(File.dirname(__FILE__), 'do_mock'))
30
15
  require File.expand_path(File.join(File.dirname(__FILE__), 'do_mock2'))
@@ -2,14 +2,14 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
3
  describe DataObjects::Transaction do
4
4
 
5
- before do
5
+ before :each do
6
6
  @connection = mock("connection")
7
- DataObjects::Connection.expects(:new).with("mock://mock/mock").once.returns(@connection)
7
+ DataObjects::Connection.should_receive(:new).with("mock://mock/mock").once.and_return(@connection)
8
8
  @transaction = DataObjects::Transaction.new("mock://mock/mock")
9
9
  end
10
10
 
11
11
  it "should have a HOST constant" do
12
- DataObjects::Transaction::HOST.should.not == nil?
12
+ DataObjects::Transaction::HOST.should_not == nil?
13
13
  end
14
14
 
15
15
  describe "#initialize" do
@@ -17,24 +17,22 @@ describe DataObjects::Transaction do
17
17
  @transaction.connection.should == @connection
18
18
  end
19
19
  it "should provide an id" do
20
- @transaction.id.should.not == nil
20
+ @transaction.id.should_not == nil
21
21
  end
22
22
  it "should provide a unique id" do
23
- DataObjects::Connection.expects(:new).with("mock://mock/mock2").once.returns(@connection)
24
- @transaction.id.should.not == DataObjects::Transaction.new("mock://mock/mock2").id
23
+ DataObjects::Connection.should_receive(:new).with("mock://mock/mock2").once.and_return(@connection)
24
+ @transaction.id.should_not == DataObjects::Transaction.new("mock://mock/mock2").id
25
25
  end
26
26
  end
27
-
28
27
  describe "#close" do
29
28
  it "should close its connection" do
30
- @connection.expects(:close).once
31
- should.not.raise(DataObjects::TransactionError) { @transaction.close }
29
+ @connection.should_receive(:close).once
30
+ lambda { @transaction.close }.should_not raise_error(DataObjects::TransactionError)
32
31
  end
33
32
  end
34
-
35
33
  [:prepare, :commit_prepared, :rollback_prepared].each do |meth|
36
34
  it "should raise NotImplementedError on #{meth}" do
37
- should.raise(NotImplementedError) { @transaction.send(meth) }
35
+ lambda { @transaction.send(meth) }.should raise_error(NotImplementedError)
38
36
  end
39
37
  end
40
38
 
data/spec/uri_spec.rb CHANGED
@@ -1,44 +1,52 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
3
  describe DataObjects::URI do
4
- before do
5
- @uri = DataObjects::URI.parse('mock://username:password@localhost:12345/path?encoding=utf8#fragment')
6
- end
4
+ subject { described_class.parse(uri) }
7
5
 
8
- it "should parse the scheme part" do
9
- @uri.scheme.should == "mock"
10
- end
6
+ context 'parsing parts' do
7
+ let(:uri) { 'mock://username:password@localhost:12345/path?encoding=utf8#fragment' }
11
8
 
12
- it "should parse the user part" do
13
- @uri.user.should == "username"
14
- end
9
+ its(:scheme) { should == 'mock' }
10
+ its(:user) { should == 'username' }
11
+ its(:password) { should == 'password' }
12
+ its(:host) { should == 'localhost' }
13
+ its(:port) { should == 12345 }
14
+ its(:path) { should == '/path' }
15
+ its(:query) { should == { 'encoding' => 'utf8' } }
16
+ its(:fragment) { should == 'fragment' }
15
17
 
16
- it "should parse the password part" do
17
- @uri.password.should == "password"
18
+ it 'should provide a correct string representation' do
19
+ subject.to_s.should == 'mock://username:password@localhost:12345/path?encoding=utf8#fragment'
20
+ end
18
21
  end
19
22
 
20
- it "should parse the host part" do
21
- @uri.host.should == "localhost"
22
- end
23
+ context 'parsing JDBC URL parts' do
24
+ let(:uri) { 'jdbc:mock://username:password@localhost:12345/path?encoding=utf8#fragment' }
23
25
 
24
- it "should parse the port part" do
25
- @uri.port.should == 12345
26
- end
26
+ its(:scheme) { should == 'jdbc' }
27
+ its(:subscheme) { should == 'mock' }
28
+ its(:user) { should == 'username' }
29
+ its(:password) { should == 'password' }
30
+ its(:host) { should == 'localhost' }
31
+ its(:port) { should == 12345 }
32
+ its(:path) { should == '/path' }
33
+ its(:query) { should == { 'encoding' => 'utf8' } }
34
+ its(:fragment) { should == 'fragment' }
27
35
 
28
- it "should parse the path part" do
29
- @uri.path.should == "/path"
36
+ it 'should provide a correct string representation' do
37
+ subject.to_s.should == 'jdbc:mock://username:password@localhost:12345/path?encoding=utf8#fragment'
38
+ end
30
39
  end
31
40
 
32
- it "should parse the query part" do
33
- @uri.query.should == { "encoding" => "utf8" }
34
- end
41
+ context 'parsing parts' do
42
+ let(:uri) { 'java:comp/env/jdbc/TestDataSource' }
35
43
 
36
- it "should parse the fragment part" do
37
- @uri.fragment.should == "fragment"
38
- end
44
+ its(:scheme) { should == 'java' }
45
+ its(:path) { should == 'comp/env/jdbc/TestDataSource' }
39
46
 
40
- it "should provide a correct string representation" do
41
- @uri.to_s.should == 'mock://username:password@localhost:12345/path?encoding=utf8#fragment'
47
+ it 'should provide a correct string representation' do
48
+ subject.to_s.should == 'java:comp/env/jdbc/TestDataSource'
49
+ end
42
50
  end
43
51
 
44
52
  end
data/tasks/spec.rake CHANGED
@@ -1,21 +1,12 @@
1
- # Specs
1
+ require 'rspec/core/rake_task'
2
2
 
3
- require 'rake/testtask'
4
- Rake::TestTask.new(:spec) do |spec|
5
- spec.libs << 'lib' << 'spec'
6
- spec.pattern = 'spec/**/*_spec.rb'
7
- spec.verbose = true
3
+ RSpec::Core::RakeTask.new(:spec) do |spec|
4
+ spec.pattern = './spec/**/*_spec.rb'
5
+ spec.skip_bundler = true
8
6
  end
9
7
 
10
- begin
11
- require 'rcov/rcovtask'
12
- Rcov::RcovTask.new do |spec|
13
- spec.libs << 'spec'
14
- spec.pattern = 'spec/**/*_spec.rb'
15
- spec.verbose = true
16
- end
17
- rescue LoadError
18
- task :rcov do
19
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
20
- end
8
+ RSpec::Core::RakeTask.new(:rcov) do |rcov|
9
+ rcov.pattern = "./spec/**/*_spec.rb"
10
+ rcov.rcov = true
11
+ rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
21
12
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_objects
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
5
- prerelease: false
4
+ hash: 977940494
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 10
9
- - 3
10
- version: 0.10.3
9
+ - 4
10
+ - rc1
11
+ version: 0.10.4.rc1
11
12
  platform: ruby
12
13
  authors:
13
14
  - Dirkjan Bussink
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-01-30 00:00:00 +01:00
19
+ date: 2011-03-29 00:00:00 +02:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -34,39 +35,24 @@ dependencies:
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  - !ruby/object:Gem::Dependency
37
- name: bacon
38
+ name: rspec
38
39
  prerelease: false
39
40
  requirement: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ~>
43
44
  - !ruby/object:Gem::Version
44
- hash: 13
45
+ hash: 9
45
46
  segments:
46
- - 1
47
- - 1
48
- version: "1.1"
47
+ - 2
48
+ - 5
49
+ version: "2.5"
49
50
  type: :development
50
51
  version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: mocha
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 25
60
- segments:
61
- - 0
62
- - 9
63
- version: "0.9"
64
- type: :development
65
- version_requirements: *id003
66
52
  - !ruby/object:Gem::Dependency
67
53
  name: yard
68
54
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
70
56
  none: false
71
57
  requirements:
72
58
  - - ~>
@@ -77,7 +63,7 @@ dependencies:
77
63
  - 5
78
64
  version: "0.5"
79
65
  type: :development
80
- version_requirements: *id004
66
+ version_requirements: *id003
81
67
  description: Provide a standard and simplified API for communicating with RDBMS from Ruby
82
68
  email: d.bussink@gmail.com
83
69
  executables: []
@@ -108,32 +94,31 @@ files:
108
94
  - lib/data_objects/quoting.rb
109
95
  - lib/data_objects/reader.rb
110
96
  - lib/data_objects/result.rb
111
- - lib/data_objects/spec/bacon.rb
112
- - lib/data_objects/spec/command_spec.rb
113
- - lib/data_objects/spec/connection_spec.rb
114
- - lib/data_objects/spec/encoding_spec.rb
115
- - lib/data_objects/spec/error/sql_error_spec.rb
116
- - lib/data_objects/spec/helpers/immediate_red_green_output.rb
117
- - lib/data_objects/spec/helpers/pending.rb
118
- - lib/data_objects/spec/helpers/ssl.rb
119
- - lib/data_objects/spec/quoting_spec.rb
120
- - lib/data_objects/spec/reader_spec.rb
121
- - lib/data_objects/spec/result_spec.rb
122
- - lib/data_objects/spec/typecast/array_spec.rb
123
- - lib/data_objects/spec/typecast/bigdecimal_spec.rb
124
- - lib/data_objects/spec/typecast/boolean_spec.rb
125
- - lib/data_objects/spec/typecast/byte_array_spec.rb
126
- - lib/data_objects/spec/typecast/class_spec.rb
127
- - lib/data_objects/spec/typecast/date_spec.rb
128
- - lib/data_objects/spec/typecast/datetime_spec.rb
129
- - lib/data_objects/spec/typecast/float_spec.rb
130
- - lib/data_objects/spec/typecast/integer_spec.rb
131
- - lib/data_objects/spec/typecast/ipaddr_spec.rb
132
- - lib/data_objects/spec/typecast/nil_spec.rb
133
- - lib/data_objects/spec/typecast/other_spec.rb
134
- - lib/data_objects/spec/typecast/range_spec.rb
135
- - lib/data_objects/spec/typecast/string_spec.rb
136
- - lib/data_objects/spec/typecast/time_spec.rb
97
+ - lib/data_objects/spec/lib/pending_helpers.rb
98
+ - lib/data_objects/spec/lib/ssl.rb
99
+ - lib/data_objects/spec/setup.rb
100
+ - lib/data_objects/spec/shared/command_spec.rb
101
+ - lib/data_objects/spec/shared/connection_spec.rb
102
+ - lib/data_objects/spec/shared/encoding_spec.rb
103
+ - lib/data_objects/spec/shared/error/sql_error_spec.rb
104
+ - lib/data_objects/spec/shared/quoting_spec.rb
105
+ - lib/data_objects/spec/shared/reader_spec.rb
106
+ - lib/data_objects/spec/shared/result_spec.rb
107
+ - lib/data_objects/spec/shared/typecast/array_spec.rb
108
+ - lib/data_objects/spec/shared/typecast/bigdecimal_spec.rb
109
+ - lib/data_objects/spec/shared/typecast/boolean_spec.rb
110
+ - lib/data_objects/spec/shared/typecast/byte_array_spec.rb
111
+ - lib/data_objects/spec/shared/typecast/class_spec.rb
112
+ - lib/data_objects/spec/shared/typecast/date_spec.rb
113
+ - lib/data_objects/spec/shared/typecast/datetime_spec.rb
114
+ - lib/data_objects/spec/shared/typecast/float_spec.rb
115
+ - lib/data_objects/spec/shared/typecast/integer_spec.rb
116
+ - lib/data_objects/spec/shared/typecast/ipaddr_spec.rb
117
+ - lib/data_objects/spec/shared/typecast/nil_spec.rb
118
+ - lib/data_objects/spec/shared/typecast/other_spec.rb
119
+ - lib/data_objects/spec/shared/typecast/range_spec.rb
120
+ - lib/data_objects/spec/shared/typecast/string_spec.rb
121
+ - lib/data_objects/spec/shared/typecast/time_spec.rb
137
122
  - lib/data_objects/transaction.rb
138
123
  - lib/data_objects/uri.rb
139
124
  - lib/data_objects/utilities.rb
@@ -148,7 +133,6 @@ files:
148
133
  - spec/spec_helper.rb
149
134
  - spec/transaction_spec.rb
150
135
  - spec/uri_spec.rb
151
- - tasks/metrics.rake
152
136
  - tasks/release.rake
153
137
  - tasks/spec.rake
154
138
  - tasks/yard.rake
@@ -158,8 +142,8 @@ homepage: http://github.com/datamapper/do
158
142
  licenses: []
159
143
 
160
144
  post_install_message:
161
- rdoc_options:
162
- - --charset=UTF-8
145
+ rdoc_options: []
146
+
163
147
  require_paths:
164
148
  - lib
165
149
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -1,9 +0,0 @@
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,217 +0,0 @@
1
- shared 'a Connection' do
2
-
3
- setup_test_environment
4
-
5
- before do
6
- @connection = DataObjects::Connection.new(CONFIG.uri)
7
- end
8
-
9
- after do
10
- @connection.close
11
- end
12
-
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
15
-
16
- it 'should respond to #dispose' do @connection.should.respond_to(:dispose) end
17
-
18
- describe 'dispose' do
19
-
20
- describe 'on open connection' do
21
-
22
- before do
23
- @open_connection = DataObjects::Connection.new("#{@driver}://#{@user}:#{@password}@#{@host}:#{@port}#{@database}")
24
- @open_connection.detach
25
- end
26
-
27
- after do
28
- @open_connection.close
29
- end
30
-
31
- it 'dispose should be true' do
32
- @open_connection.dispose.should.be.true
33
- end
34
-
35
- end
36
-
37
- describe 'on closed connection' do
38
-
39
- before do
40
- @closed_connection = DataObjects::Connection.new("#{@driver}://#{@user}:#{@password}@#{@host}:#{@port}#{@database}")
41
- @closed_connection.detach
42
- @closed_connection.dispose
43
- end
44
-
45
- after do
46
- @closed_connection.close
47
- end
48
-
49
- it 'dispose should be false' do
50
- @closed_connection.dispose.should.be.false
51
- end
52
-
53
- it 'should raise an error on creating a command' do
54
- should.raise(DataObjects::ConnectionError) {
55
- @closed_connection.create_command("INSERT INTO non_existent_table (tester) VALUES (1)").execute_non_query
56
- }
57
- end
58
- end
59
-
60
- end
61
-
62
- it 'should respond to #create_command' do @connection.should.respond_to(:create_command) end
63
-
64
- describe 'create_command' do
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
68
- end
69
-
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
77
-
78
- after do
79
- @open_connection.close if @open_connection
80
- end
81
-
82
- it 'should open with an uri object' do
83
- uri = DataObjects::URI.new(
84
- @driver,
85
- @user,
86
- @password,
87
- @host,
88
- @port && @port.to_i,
89
- @database,
90
- nil, nil
91
- )
92
- test_connection(DataObjects::Connection.new(uri)).should == 1
93
- end
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)
107
- end
108
-
109
- describe 'with an invalid URI' do
110
-
111
- # FIXME JRuby (and MRI): Should these be ArgumentError or DataObjects::SQLError?
112
-
113
- def connecting_with(uri)
114
- lambda { DataObjects::Connection.new(uri) }
115
- end
116
-
117
- it 'should raise an error if no database specified' do
118
- connecting_with("#{@driver}://#{@user}:#{@password}@#{@host}:#{@port}").should.raise(ArgumentError, DataObjects::Error)
119
- end
120
-
121
- it 'should raise an error if bad username is given' do
122
- connecting_with("#{@driver}://thisreallyshouldntexist:#{@password}@#{@host}:#{@port}#{@database}").should.raise(ArgumentError, DataObjects::Error)
123
- end
124
-
125
- it 'should raise an error if bad password is given' do
126
- connecting_with("#{@driver}://#{@user}:completelyincorrectpassword:#{@host}:#{@port}#{@database}").should.raise(ArgumentError, DataObjects::Error)
127
- end
128
-
129
- it 'should raise an error if an invalid port is given' do
130
- connecting_with("#{@driver}://#{@user}:#{@password}:#{@host}:648646543#{@database}").should.raise(ArgumentError, DataObjects::Error)
131
- end
132
-
133
- it 'should raise an error if an invalid database is given' do
134
- connecting_with("#{@driver}://#{@user}:#{@password}:#{@host}:#{@port}/someweirddatabase").should.raise(ArgumentError, DataObjects::Error)
135
- end
136
-
137
- it 'should raise an error with a meaningless URI' do
138
- connecting_with("#{@driver}://peekaboo$2!@#4543").should.raise(Addressable::URI::InvalidURIError)
139
- end
140
-
141
- end
142
-
143
- end
144
-
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
161
-
162
- if DataObjectsSpecHelpers.test_environment_supports_ssl?
163
- describe 'connecting with SSL' do
164
-
165
- it 'should connect securely' do
166
- DataObjects::Connection.new("#{CONFIG.uri}?#{CONFIG.ssl}").secure?.should.be.true
167
- end
168
-
169
- end
170
- end
171
-
172
- describe 'connecting without SSL' do
173
-
174
- it 'should not connect securely' do
175
- DataObjects::Connection.new(CONFIG.uri).secure?.should.be.false
176
- end
177
-
178
- end
179
-
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