do_mysql 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module DataObjects
2
+ module Mysql
3
+ VERSION = "0.9.3"
4
+ end
5
+ end
@@ -4,10 +4,14 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
4
  describe DataObjects::Mysql do
5
5
  include MysqlSpecHelpers
6
6
 
7
- before :all do
7
+ before :each do
8
8
  setup_test_environment
9
9
  end
10
10
 
11
+ after :each do
12
+ teardown_test_environment
13
+ end
14
+
11
15
  it "should expose the proper DataObjects classes" do
12
16
  DataObjects::Mysql.const_get('Connection').should_not be_nil
13
17
  DataObjects::Mysql.const_get('Command').should_not be_nil
@@ -17,8 +21,9 @@ describe DataObjects::Mysql do
17
21
 
18
22
  it "should connect successfully via TCP" do
19
23
  pending "Problems parsing regular connection URIs vs. JDBC URLs" if JRUBY
20
- connection = DataObjects::Mysql::Connection.new("mysql://root@127.0.0.1:3306/do_mysql_test")
24
+ connection = DataObjects::Connection.new("mysql://root@127.0.0.1:3306/do_mysql_test")
21
25
  connection.should_not be_using_socket
26
+ connection.close
22
27
  end
23
28
 
24
29
  #
@@ -33,23 +38,26 @@ describe DataObjects::Mysql do
33
38
 
34
39
  it "should return the current character set" do
35
40
  pending "Problems parsing regular connection URIs vs. JDBC URLs" if JRUBY
36
- connection = DataObjects::Mysql::Connection.new("mysql://root@localhost:3306/do_mysql_test")
41
+ connection = DataObjects::Connection.new("mysql://root@localhost:3306/do_mysql_test")
37
42
  connection.character_set.should == "utf8"
43
+ connection.close
38
44
  end
39
45
 
40
46
  it "should support changing the character set" do
41
47
  pending "Problems parsing regular connection URIs vs. JDBC URLs" if JRUBY
42
- connection = DataObjects::Mysql::Connection.new("mysql://root@localhost:3306/do_mysql_test/?charset=latin1")
48
+ connection = DataObjects::Connection.new("mysql://root@localhost:3306/do_mysql_test/?charset=latin1")
43
49
  connection.character_set.should == "latin1"
50
+ connection.close
44
51
 
45
- @connection = DataObjects::Mysql::Connection.new("mysql://root@localhost:3306/do_mysql_test/?charset=utf8")
46
- @connection.character_set.should == "utf8"
52
+ connection = DataObjects::Connection.new("mysql://root@localhost:3306/do_mysql_test/?charset=utf8")
53
+ connection.character_set.should == "utf8"
54
+ connection.close
47
55
  end
48
56
 
49
57
  it "should raise an error when opened with an invalid server uri" do
50
58
  pending "Problems parsing regular connection URIs vs. JDBC URLs" if JRUBY
51
59
  def connecting_with(uri)
52
- lambda { DataObjects::Mysql::Connection.new(uri) }
60
+ lambda { DataObjects::Connection.new(uri) }
53
61
  end
54
62
 
55
63
  # Missing database name
@@ -78,13 +86,48 @@ end
78
86
  describe DataObjects::Mysql::Connection do
79
87
  include MysqlSpecHelpers
80
88
 
81
- before :all do
89
+ before :each do
82
90
  setup_test_environment
83
91
  end
84
92
 
93
+ after :each do
94
+ teardown_test_environment
95
+ end
96
+
85
97
  it "should raise an error when attempting to execute a bad query" do
86
98
  lambda { @connection.create_command("INSERT INTO non_existant_table (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError)
87
- lambda { @connection.create_command("SELECT * FROM non_existant table").execute_reader }.should raise_error(MysqlError)
99
+ end
100
+
101
+ it "should raise an error when executing a bad reader" do
102
+ lambda { @connection.create_command("SELECT * FROM non_existant_table").execute_reader }.should raise_error(MysqlError)
103
+ end
104
+
105
+ it "should close the connection when executing a bad query" do
106
+ lambda { @connection.create_command("INSERT INTO non_exista (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError)
107
+ @connection.instance_variable_get(:@connection).should == nil
108
+ end
109
+
110
+ it "should flush the pool when executing a bad query" do
111
+ pool = @connection.instance_variable_get(:@__pool)
112
+ lambda { @connection.create_command("INSERT INTO non_exista (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError)
113
+ Extlib::Pooling.pools.detect { |p| p == pool }.instance_variable_get(:@available).size.should == 0
114
+ end
115
+
116
+ it "should delete itself from the pool" do
117
+ pool = @connection.instance_variable_get(:@__pool)
118
+ count = pool.reserved_count
119
+ lambda { @connection.create_command("INSERT INTO non_exista (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError)
120
+ Extlib::Pooling.pools.detect { |p| p == pool }.instance_variable_get(:@reserved_count).should == count-1
121
+ end
122
+
123
+ it "should not raise an error error executing a non query on a closed connection" do
124
+ lambda { @connection.create_command("INSERT INTO non_existant_table (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError)
125
+ lambda { @connection.create_command("INSERT INTO non_existant_table (tester) VALUES (1)").execute_non_query }.should raise_error(MysqlError, "This connection has already been closed.")
126
+ end
127
+
128
+ it "should not raise an error executing a reader on a closed connection" do
129
+ lambda { @connection.create_command("SELECT * FROM non_existant_table").execute_reader }.should raise_error(MysqlError)
130
+ lambda { @connection.create_command("SELECT * FROM non_existant_table").execute_reader }.should raise_error(MysqlError, "This connection has already been closed.")
88
131
  end
89
132
 
90
133
  end
@@ -92,10 +135,14 @@ end
92
135
  describe DataObjects::Mysql::Reader do
93
136
  include MysqlSpecHelpers
94
137
 
95
- before :all do
138
+ before :each do
96
139
  setup_test_environment
97
140
  end
98
141
 
142
+ after :each do
143
+ teardown_test_environment
144
+ end
145
+
99
146
  it "should raise an error when you pass too many or too few types for the expected result set" do
100
147
  lambda { select("SELECT name, fired_at FROM users", [String, DateTime, Integer]) }.should raise_error(MysqlError)
101
148
  end
@@ -159,6 +206,14 @@ describe DataObjects::Mysql::Reader do
159
206
 
160
207
  describe "Date, Time, and DateTime" do
161
208
 
209
+ it "should return nil when the time is 0" do
210
+ id = insert("INSERT INTO users (name, fired_at) VALUES ('James', 0);")
211
+ select("SELECT fired_at FROM users WHERE id = ?", [Time], id) do |reader|
212
+ reader.values.last.should be_nil
213
+ end
214
+ exec("DELETE FROM users WHERE id = ?", id)
215
+ end
216
+
162
217
  it "should return DateTimes using the current locale's Time Zone" do
163
218
  date = DateTime.now
164
219
  id = insert("INSERT INTO users (name, fired_at) VALUES (?, ?)", 'Sam', date)
@@ -236,6 +291,11 @@ describe DataObjects::Mysql::Reader do
236
291
  lambda { command.execute_non_query }.should raise_error(Exception)
237
292
  end
238
293
 
294
+ # it "should raise an error when inserting the wrong typed data" do
295
+ # command = @connection.create_command("UPDATE invoices SET invoice_number = ?")
296
+ # command.execute_non_query(1)
297
+ # end
298
+
239
299
  end
240
300
 
241
301
  end
@@ -5,12 +5,16 @@ describe DataObjects::Mysql::Command do
5
5
 
6
6
  before(:each) do
7
7
  @connection = if JRUBY
8
- DataObjects::Mysql::Connection.new(DO_MYSQL_SPEC_JDBC_URI)
8
+ DataObjects::Connection.new(DO_MYSQL_SPEC_JDBC_URI)
9
9
  else
10
- DataObjects::Mysql::Connection.new(DO_MYSQL_SPEC_URI)
10
+ DataObjects::Connection.new(DO_MYSQL_SPEC_URI)
11
11
  end
12
12
  end
13
13
 
14
+ after(:each) do
15
+ @connection.close
16
+ end
17
+
14
18
  describe "Executing a Reader" do
15
19
 
16
20
  it "should log reader queries when the level is Debug (0)" do
@@ -18,7 +22,8 @@ describe DataObjects::Mysql::Command do
18
22
  @mock_logger = mock('MockLogger', :level => 0)
19
23
  DataObjects::Mysql.should_receive(:logger).and_return(@mock_logger)
20
24
  @mock_logger.should_receive(:debug).with("SELECT * FROM widgets WHERE name = 'Scott'")
21
- command.execute_reader('Scott')
25
+
26
+ command.execute_reader('Scott').close # Readers must be closed!
22
27
  end
23
28
 
24
29
  it "shouldn't log reader queries when the level isn't Debug (0)" do
@@ -26,7 +31,7 @@ describe DataObjects::Mysql::Command do
26
31
  @mock_logger = mock('MockLogger', :level => 1)
27
32
  DataObjects::Mysql.should_receive(:logger).and_return(@mock_logger)
28
33
  @mock_logger.should_not_receive(:debug)
29
- command.execute_reader('Scott')
34
+ command.execute_reader('Scott').close # Readers must be closed!
30
35
  end
31
36
  end
32
37
 
@@ -5,10 +5,14 @@ require 'date'
5
5
  describe DataObjects::Mysql::Command, "Quoting" do
6
6
  include MysqlSpecHelpers
7
7
 
8
- before :all do
8
+ before :each do
9
9
  setup_test_environment
10
10
  end
11
11
 
12
+ after :each do
13
+ teardown_test_environment
14
+ end
15
+
12
16
  it "should escape strings properly" do
13
17
  command = @connection.create_command("SELECT * FROM widgets WHERE name = ?")
14
18
  command.quote_string("Willy O'Hare & Johnny O'Toole").should == "'Willy O\\'Hare & Johnny O\\'Toole'".dup
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --colour
@@ -32,8 +32,8 @@ DataObjects::Mysql.logger = DataObjects::Logger.new(log_path, 0)
32
32
  at_exit { DataObjects.logger.flush }
33
33
 
34
34
  # use different, JDBC-style URLs for JRuby, for the time-being
35
- DO_MYSQL_SPEC_URI = ENV["DO_MYSQL_SPEC_URI"] || "mysql://root@127.0.0.1:3306/do_mysql_test"
36
- DO_MYSQL_SPEC_JDBC_URI = ENV["DO_MYSQL_SPEC_JDBC_URI"] || "jdbc:mysql://localhost:3306/do_mysql_test?user=root"
35
+ DO_MYSQL_SPEC_URI = Addressable::URI::parse(ENV["DO_MYSQL_SPEC_URI"] || "mysql://root@127.0.0.1:3306/do_mysql_test")
36
+ DO_MYSQL_SPEC_JDBC_URI = Addressable::URI::parse(ENV["DO_MYSQL_SPEC_JDBC_URI"] || "jdbc:mysql://localhost:3306/do_mysql_test?user=root")
37
37
 
38
38
  module MysqlSpecHelpers
39
39
  def insert(query, *args)
@@ -59,11 +59,11 @@ module MysqlSpecHelpers
59
59
 
60
60
  def setup_test_environment
61
61
  if JRUBY # use different, JDBC-style URLs for JRuby, for the time-being
62
- @connection = DataObjects::Mysql::Connection.new(DO_MYSQL_SPEC_JDBC_URI)
63
- @secondary_connection = DataObjects::Mysql::Connection.new(DO_MYSQL_SPEC_JDBC_URI)
62
+ @connection = DataObjects::Connection.new(DO_MYSQL_SPEC_JDBC_URI)
63
+ @secondary_connection = DataObjects::Connection.new(DO_MYSQL_SPEC_JDBC_URI)
64
64
  elsif
65
- @connection = DataObjects::Mysql::Connection.new(DO_MYSQL_SPEC_URI)
66
- @secondary_connection = DataObjects::Mysql::Connection.new(DO_MYSQL_SPEC_URI)
65
+ @connection = DataObjects::Connection.new(DO_MYSQL_SPEC_URI)
66
+ @secondary_connection = DataObjects::Connection.new(DO_MYSQL_SPEC_URI)
67
67
  end
68
68
 
69
69
  @connection.create_command(<<-EOF).execute_non_query
@@ -127,5 +127,11 @@ module MysqlSpecHelpers
127
127
  insert into widgets(code, name, shelf_location, description, image_data, ad_description, ad_image, whitepaper_text, cad_drawing, super_number) VALUES ('W#{n.to_s.rjust(7,"0")}', 'Widget #{n}', 'A14', 'This is a description', 'IMAGE DATA', 'Buy this product now!', 'AD IMAGE DATA', 'Utilizing blah blah blah', 'CAD DRAWING', 1234);
128
128
  EOF
129
129
  end
130
+
131
+ end
132
+
133
+ def teardown_test_environment
134
+ @connection.close
135
+ @secondary_connection.close
130
136
  end
131
137
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Bauer
@@ -9,47 +9,70 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-25 00:00:00 -05:00
12
+ date: 2008-07-24 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: data_objects
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - "="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.9.2
23
+ version: 0.9.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
23
34
  version:
24
35
  description: A DataObject.rb driver for MySQL
25
- email: bauer.mail@gmail.com
36
+ email:
37
+ - bauer.mail@gmail.com
26
38
  executables: []
27
39
 
28
40
  extensions:
29
41
  - ext/extconf.rb
30
42
  extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - README.txt
46
+ files:
47
+ - History.txt
31
48
  - LICENSE
49
+ - Manifest.txt
50
+ - README.txt
51
+ - Rakefile
32
52
  - TODO
33
- files:
53
+ - buildfile
54
+ - ext-java/src/main/java/DoMysqlExtService.java
55
+ - ext-java/src/main/java/do_mysql/MySqlDriverDefinition.java
34
56
  - ext/do_mysql_ext.c
35
57
  - ext/extconf.rb
36
- - lib/do_mysql/transaction.rb
37
58
  - lib/do_mysql.rb
59
+ - lib/do_mysql/transaction.rb
60
+ - lib/do_mysql/version.rb
38
61
  - spec/integration/do_mysql_spec.rb
39
62
  - spec/integration/logging_spec.rb
40
63
  - spec/integration/quoting_spec.rb
64
+ - spec/spec.opts
41
65
  - spec/spec_helper.rb
42
66
  - spec/unit/transaction_spec.rb
43
- - Rakefile
44
- - LICENSE
45
- - TODO
46
67
  has_rdoc: false
47
68
  homepage: http://rubyforge.org/projects/dorb
48
69
  post_install_message:
49
- rdoc_options: []
50
-
70
+ rdoc_options:
71
+ - --main
72
+ - README.txt
51
73
  require_paths:
52
74
  - lib
75
+ - ext
53
76
  required_ruby_version: !ruby/object:Gem::Requirement
54
77
  requirements:
55
78
  - - ">="
@@ -65,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
88
  requirements: []
66
89
 
67
90
  rubyforge_project: dorb
68
- rubygems_version: 1.0.1
91
+ rubygems_version: 1.2.0
69
92
  signing_key:
70
93
  specification_version: 2
71
94
  summary: A DataObject.rb driver for MySQL