mysql2 0.4.6 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,9 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  RSpec.describe Mysql2::Error do
6
- let(:client) { Mysql2::Client.new(DatabaseCredentials['root']) }
7
-
8
4
  let(:error) do
9
5
  begin
10
- client.query("HAHAHA")
6
+ @client.query("HAHAHA")
11
7
  rescue Mysql2::Error => e
12
8
  error = e
13
9
  end
@@ -28,7 +24,7 @@ RSpec.describe Mysql2::Error do
28
24
  let(:valid_utf8) { '造字' }
29
25
  let(:error) do
30
26
  begin
31
- client.query(valid_utf8)
27
+ @client.query(valid_utf8)
32
28
  rescue Mysql2::Error => e
33
29
  e
34
30
  end
@@ -37,15 +33,13 @@ RSpec.describe Mysql2::Error do
37
33
  let(:invalid_utf8) { ["e5c67d1f"].pack('H*').force_encoding(Encoding::UTF_8) }
38
34
  let(:bad_err) do
39
35
  begin
40
- client.query(invalid_utf8)
36
+ @client.query(invalid_utf8)
41
37
  rescue Mysql2::Error => e
42
38
  e
43
39
  end
44
40
  end
45
41
 
46
42
  before do
47
- pending('String#encoding is not defined') unless String.public_method_defined?(:encoding)
48
-
49
43
  # sanity check
50
44
  expect(valid_utf8.encoding).to eql(Encoding::UTF_8)
51
45
  expect(valid_utf8).to be_valid_encoding
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'spec_helper'
3
2
 
4
3
  RSpec.describe Mysql2::Result do
@@ -27,13 +26,13 @@ RSpec.describe Mysql2::Result do
27
26
  end
28
27
 
29
28
  it "should raise a Mysql2::Error exception upon a bad query" do
30
- expect {
29
+ expect do
31
30
  @client.query "bad sql"
32
- }.to raise_error(Mysql2::Error)
31
+ end.to raise_error(Mysql2::Error)
33
32
 
34
- expect {
33
+ expect do
35
34
  @client.query "SELECT 1"
36
- }.not_to raise_error
35
+ end.not_to raise_error
37
36
  end
38
37
 
39
38
  it "should respond to #count, which is aliased as #size" do
@@ -62,13 +61,13 @@ RSpec.describe Mysql2::Result do
62
61
  end
63
62
 
64
63
  it "should yield rows as hash's with symbol keys if :symbolize_keys was set to true" do
65
- @result.each(:symbolize_keys => true) do |row|
64
+ @result.each(symbolize_keys: true) do |row|
66
65
  expect(row.keys.first).to be_an_instance_of(Symbol)
67
66
  end
68
67
  end
69
68
 
70
69
  it "should be able to return results as an array" do
71
- @result.each(:as => :array) do |row|
70
+ @result.each(as: :array) do |row|
72
71
  expect(row).to be_an_instance_of(Array)
73
72
  end
74
73
  end
@@ -78,60 +77,58 @@ RSpec.describe Mysql2::Result do
78
77
  end
79
78
 
80
79
  it "should not cache previously yielded results if cache_rows is disabled" do
81
- result = @client.query "SELECT 1", :cache_rows => false
80
+ result = @client.query "SELECT 1", cache_rows: false
82
81
  expect(result.first.object_id).not_to eql(result.first.object_id)
83
82
  end
84
83
 
85
84
  it "should be able to iterate a second time even if cache_rows is disabled" do
86
- result = @client.query "SELECT 1 UNION SELECT 2", :cache_rows => false
85
+ result = @client.query "SELECT 1 UNION SELECT 2", cache_rows: false
87
86
  expect(result.to_a).to eql(result.to_a)
88
87
  end
89
88
 
90
89
  it "should yield different value for #first if streaming" do
91
- result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
90
+ result = @client.query "SELECT 1 UNION SELECT 2", stream: true, cache_rows: false
92
91
  expect(result.first).not_to eql(result.first)
93
92
  end
94
93
 
95
94
  it "should yield the same value for #first if streaming is disabled" do
96
- result = @client.query "SELECT 1 UNION SELECT 2", :stream => false
95
+ result = @client.query "SELECT 1 UNION SELECT 2", stream: false
97
96
  expect(result.first).to eql(result.first)
98
97
  end
99
98
 
100
99
  it "should throw an exception if we try to iterate twice when streaming is enabled" do
101
- result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
100
+ result = @client.query "SELECT 1 UNION SELECT 2", stream: true, cache_rows: false
102
101
 
103
- expect {
102
+ expect do
104
103
  result.each.to_a
105
104
  result.each.to_a
106
- }.to raise_exception(Mysql2::Error)
105
+ end.to raise_exception(Mysql2::Error)
107
106
  end
108
107
  end
109
108
 
110
109
  context "#fields" do
111
- before(:each) do
112
- @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1")
113
- end
110
+ let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1") }
114
111
 
115
112
  it "method should exist" do
116
- expect(@test_result).to respond_to(:fields)
113
+ expect(test_result).to respond_to(:fields)
117
114
  end
118
115
 
119
116
  it "should return an array of field names in proper order" do
120
117
  result = @client.query "SELECT 'a', 'b', 'c'"
121
- expect(result.fields).to eql(%w(a b c))
118
+ expect(result.fields).to eql(%w[a b c])
122
119
  end
123
120
  end
124
121
 
125
122
  context "streaming" do
126
123
  it "should maintain a count while streaming" do
127
- result = @client.query('SELECT 1', :stream => true, :cache_rows => false)
124
+ result = @client.query('SELECT 1', stream: true, cache_rows: false)
128
125
  expect(result.count).to eql(0)
129
126
  result.each.to_a
130
127
  expect(result.count).to eql(1)
131
128
  end
132
129
 
133
130
  it "should retain the count when mixing first and each" do
134
- result = @client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false)
131
+ result = @client.query("SELECT 1 UNION SELECT 2", stream: true, cache_rows: false)
135
132
  expect(result.count).to eql(0)
136
133
  result.first
137
134
  expect(result.count).to eql(1)
@@ -140,48 +137,44 @@ RSpec.describe Mysql2::Result do
140
137
  end
141
138
 
142
139
  it "should not yield nil at the end of streaming" do
143
- result = @client.query('SELECT * FROM mysql2_test', :stream => true, :cache_rows => false)
140
+ result = @client.query('SELECT * FROM mysql2_test', stream: true, cache_rows: false)
144
141
  result.each { |r| expect(r).not_to be_nil }
145
142
  end
146
143
 
147
144
  it "#count should be zero for rows after streaming when there were no results" do
148
145
  @client.query "USE test"
149
- result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false)
146
+ result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", stream: true, cache_rows: false)
150
147
  expect(result.count).to eql(0)
151
148
  result.each.to_a
152
149
  expect(result.count).to eql(0)
153
150
  end
154
151
 
155
152
  it "should raise an exception if streaming ended due to a timeout" do
156
- # Create an extra client instance, since we're going to time it out
157
- client = Mysql2::Client.new DatabaseCredentials['root']
158
- client.query "CREATE TEMPORARY TABLE streamingTest (val BINARY(255)) ENGINE=MEMORY"
153
+ @client.query "CREATE TEMPORARY TABLE streamingTest (val BINARY(255)) ENGINE=MEMORY"
159
154
 
160
155
  # Insert enough records to force the result set into multiple reads
161
156
  # (the BINARY type is used simply because it forces full width results)
162
157
  10000.times do |i|
163
- client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')"
158
+ @client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')"
164
159
  end
165
160
 
166
- client.query "SET net_write_timeout = 1"
167
- res = client.query "SELECT * FROM streamingTest", :stream => true, :cache_rows => false
161
+ @client.query "SET net_write_timeout = 1"
162
+ res = @client.query "SELECT * FROM streamingTest", stream: true, cache_rows: false
168
163
 
169
- expect {
164
+ expect do
170
165
  res.each_with_index do |_, i|
171
166
  # Exhaust the first result packet then trigger a timeout
172
167
  sleep 2 if i > 0 && i % 1000 == 0
173
168
  end
174
- }.to raise_error(Mysql2::Error, /Lost connection/)
169
+ end.to raise_error(Mysql2::Error, /Lost connection/)
175
170
  end
176
171
  end
177
172
 
178
173
  context "row data type mapping" do
179
- before(:each) do
180
- @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
181
- end
174
+ let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first }
182
175
 
183
176
  it "should return nil values for NULL and strings for everything else when :cast is false" do
184
- result = @client.query('SELECT null_test, tiny_int_test, bool_cast_test, int_test, date_test, enum_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast => false).first
177
+ result = @client.query('SELECT null_test, tiny_int_test, bool_cast_test, int_test, date_test, enum_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', cast: false).first
185
178
  expect(result["null_test"]).to be_nil
186
179
  expect(result["tiny_int_test"]).to eql("1")
187
180
  expect(result["bool_cast_test"]).to eql("1")
@@ -191,167 +184,137 @@ RSpec.describe Mysql2::Result do
191
184
  end
192
185
 
193
186
  it "should return nil for a NULL value" do
194
- expect(@test_result['null_test']).to be_an_instance_of(NilClass)
195
- expect(@test_result['null_test']).to eql(nil)
187
+ expect(test_result['null_test']).to be_an_instance_of(NilClass)
188
+ expect(test_result['null_test']).to eql(nil)
196
189
  end
197
190
 
198
191
  it "should return String for a BIT(64) value" do
199
- expect(@test_result['bit_test']).to be_an_instance_of(String)
200
- expect(@test_result['bit_test']).to eql("\000\000\000\000\000\000\000\005")
192
+ expect(test_result['bit_test']).to be_an_instance_of(String)
193
+ expect(test_result['bit_test']).to eql("\000\000\000\000\000\000\000\005")
201
194
  end
202
195
 
203
196
  it "should return String for a BIT(1) value" do
204
- expect(@test_result['single_bit_test']).to be_an_instance_of(String)
205
- expect(@test_result['single_bit_test']).to eql("\001")
197
+ expect(test_result['single_bit_test']).to be_an_instance_of(String)
198
+ expect(test_result['single_bit_test']).to eql("\001")
206
199
  end
207
200
 
208
201
  it "should return Fixnum for a TINYINT value" do
209
- expect([Fixnum, Bignum]).to include(@test_result['tiny_int_test'].class)
210
- expect(@test_result['tiny_int_test']).to eql(1)
202
+ expect(num_classes).to include(test_result['tiny_int_test'].class)
203
+ expect(test_result['tiny_int_test']).to eql(1)
211
204
  end
212
205
 
213
- it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
214
- @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (1)'
215
- id1 = @client.last_id
216
- @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (0)'
217
- id2 = @client.last_id
218
- @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'
219
- id3 = @client.last_id
206
+ context "cast booleans for TINYINT if :cast_booleans is enabled" do
207
+ # rubocop:disable Style/Semicolon
208
+ let(:id1) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 1)'; @client.last_id }
209
+ let(:id2) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 0)'; @client.last_id }
210
+ let(:id3) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'; @client.last_id }
211
+ # rubocop:enable Style/Semicolon
220
212
 
221
- result1 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast_booleans => true
222
- result2 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1', :cast_booleans => true
223
- result3 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = -1 LIMIT 1', :cast_booleans => true
224
- expect(result1.first['bool_cast_test']).to be true
225
- expect(result2.first['bool_cast_test']).to be false
226
- expect(result3.first['bool_cast_test']).to be true
213
+ after do
214
+ @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
215
+ end
227
216
 
228
- @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
217
+ it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
218
+ result1 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id1} LIMIT 1", cast_booleans: true
219
+ result2 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id2} LIMIT 1", cast_booleans: true
220
+ result3 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id3} LIMIT 1", cast_booleans: true
221
+ expect(result1.first['bool_cast_test']).to be true
222
+ expect(result2.first['bool_cast_test']).to be false
223
+ expect(result3.first['bool_cast_test']).to be true
224
+ end
229
225
  end
230
226
 
231
- it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
232
- @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'
233
- id1 = @client.last_id
234
- @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'
235
- id2 = @client.last_id
227
+ context "cast booleans for BIT(1) if :cast_booleans is enabled" do
228
+ # rubocop:disable Style/Semicolon
229
+ let(:id1) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'; @client.last_id }
230
+ let(:id2) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'; @client.last_id }
231
+ # rubocop:enable Style/Semicolon
236
232
 
237
- result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", :cast_booleans => true
238
- result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", :cast_booleans => true
239
- expect(result1.first['single_bit_test']).to be true
240
- expect(result2.first['single_bit_test']).to be false
233
+ after do
234
+ @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
235
+ end
241
236
 
242
- @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
237
+ it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
238
+ result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", cast_booleans: true
239
+ result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", cast_booleans: true
240
+ expect(result1.first['single_bit_test']).to be true
241
+ expect(result2.first['single_bit_test']).to be false
242
+ end
243
243
  end
244
244
 
245
245
  it "should return Fixnum for a SMALLINT value" do
246
- expect([Fixnum, Bignum]).to include(@test_result['small_int_test'].class)
247
- expect(@test_result['small_int_test']).to eql(10)
246
+ expect(num_classes).to include(test_result['small_int_test'].class)
247
+ expect(test_result['small_int_test']).to eql(10)
248
248
  end
249
249
 
250
250
  it "should return Fixnum for a MEDIUMINT value" do
251
- expect([Fixnum, Bignum]).to include(@test_result['medium_int_test'].class)
252
- expect(@test_result['medium_int_test']).to eql(10)
251
+ expect(num_classes).to include(test_result['medium_int_test'].class)
252
+ expect(test_result['medium_int_test']).to eql(10)
253
253
  end
254
254
 
255
255
  it "should return Fixnum for an INT value" do
256
- expect([Fixnum, Bignum]).to include(@test_result['int_test'].class)
257
- expect(@test_result['int_test']).to eql(10)
256
+ expect(num_classes).to include(test_result['int_test'].class)
257
+ expect(test_result['int_test']).to eql(10)
258
258
  end
259
259
 
260
260
  it "should return Fixnum for a BIGINT value" do
261
- expect([Fixnum, Bignum]).to include(@test_result['big_int_test'].class)
262
- expect(@test_result['big_int_test']).to eql(10)
261
+ expect(num_classes).to include(test_result['big_int_test'].class)
262
+ expect(test_result['big_int_test']).to eql(10)
263
263
  end
264
264
 
265
265
  it "should return Fixnum for a YEAR value" do
266
- expect([Fixnum, Bignum]).to include(@test_result['year_test'].class)
267
- expect(@test_result['year_test']).to eql(2009)
266
+ expect(num_classes).to include(test_result['year_test'].class)
267
+ expect(test_result['year_test']).to eql(2009)
268
268
  end
269
269
 
270
270
  it "should return BigDecimal for a DECIMAL value" do
271
- expect(@test_result['decimal_test']).to be_an_instance_of(BigDecimal)
272
- expect(@test_result['decimal_test']).to eql(10.3)
271
+ expect(test_result['decimal_test']).to be_an_instance_of(BigDecimal)
272
+ expect(test_result['decimal_test']).to eql(10.3)
273
273
  end
274
274
 
275
275
  it "should return Float for a FLOAT value" do
276
- expect(@test_result['float_test']).to be_an_instance_of(Float)
277
- expect(@test_result['float_test']).to eql(10.3)
276
+ expect(test_result['float_test']).to be_an_instance_of(Float)
277
+ expect(test_result['float_test']).to eql(10.3)
278
278
  end
279
279
 
280
280
  it "should return Float for a DOUBLE value" do
281
- expect(@test_result['double_test']).to be_an_instance_of(Float)
282
- expect(@test_result['double_test']).to eql(10.3)
281
+ expect(test_result['double_test']).to be_an_instance_of(Float)
282
+ expect(test_result['double_test']).to eql(10.3)
283
283
  end
284
284
 
285
285
  it "should return Time for a DATETIME value when within the supported range" do
286
- expect(@test_result['date_time_test']).to be_an_instance_of(Time)
287
- expect(@test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
286
+ expect(test_result['date_time_test']).to be_an_instance_of(Time)
287
+ expect(test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
288
288
  end
289
289
 
290
- if 1.size == 4 # 32bit
291
- klass = if RUBY_VERSION =~ /1.8/
292
- DateTime
293
- else
294
- Time
295
- end
296
-
297
- it "should return DateTime when timestamp is < 1901-12-13 20:45:52" do
298
- # 1901-12-13T20:45:52 is the min for 32bit Ruby 1.8
299
- r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
300
- expect(r.first['test']).to be_an_instance_of(klass)
301
- end
302
-
303
- it "should return DateTime when timestamp is > 2038-01-19T03:14:07" do
304
- # 2038-01-19T03:14:07 is the max for 32bit Ruby 1.8
305
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
306
- expect(r.first['test']).to be_an_instance_of(klass)
307
- end
308
- elsif 1.size == 8 # 64bit
309
- if RUBY_VERSION =~ /1.8/
310
- it "should return Time when timestamp is > 0138-12-31 11:59:59" do
311
- r = @client.query("SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test")
312
- expect(r.first['test']).to be_an_instance_of(Time)
313
- end
314
-
315
- it "should return DateTime when timestamp is < 0139-1-1T00:00:00" do
316
- r = @client.query("SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test")
317
- expect(r.first['test']).to be_an_instance_of(DateTime)
318
- end
319
-
320
- it "should return Time when timestamp is > 2038-01-19T03:14:07" do
321
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
322
- expect(r.first['test']).to be_an_instance_of(Time)
323
- end
324
- else
325
- it "should return Time when timestamp is < 1901-12-13 20:45:52" do
326
- r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
327
- expect(r.first['test']).to be_an_instance_of(Time)
328
- end
290
+ it "should return Time when timestamp is < 1901-12-13 20:45:52" do
291
+ r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
292
+ expect(r.first['test']).to be_an_instance_of(Time)
293
+ end
329
294
 
330
- it "should return Time when timestamp is > 2038-01-19T03:14:07" do
331
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
332
- expect(r.first['test']).to be_an_instance_of(Time)
333
- end
334
- end
295
+ it "should return Time when timestamp is > 2038-01-19T03:14:07" do
296
+ r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
297
+ expect(r.first['test']).to be_an_instance_of(Time)
335
298
  end
336
299
 
337
300
  it "should return Time for a TIMESTAMP value when within the supported range" do
338
- expect(@test_result['timestamp_test']).to be_an_instance_of(Time)
339
- expect(@test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
301
+ expect(test_result['timestamp_test']).to be_an_instance_of(Time)
302
+ expect(test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
340
303
  end
341
304
 
342
305
  it "should return Time for a TIME value" do
343
- expect(@test_result['time_test']).to be_an_instance_of(Time)
344
- expect(@test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2000-01-01 11:44:00')
306
+ expect(test_result['time_test']).to be_an_instance_of(Time)
307
+ expect(test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2000-01-01 11:44:00')
345
308
  end
346
309
 
347
310
  it "should return Date for a DATE value" do
348
- expect(@test_result['date_test']).to be_an_instance_of(Date)
349
- expect(@test_result['date_test'].strftime("%Y-%m-%d")).to eql('2010-04-04')
311
+ expect(test_result['date_test']).to be_an_instance_of(Date)
312
+ expect(test_result['date_test'].strftime("%Y-%m-%d")).to eql('2010-04-04')
350
313
  end
351
314
 
352
315
  it "should return String for an ENUM value" do
353
- expect(@test_result['enum_test']).to be_an_instance_of(String)
354
- expect(@test_result['enum_test']).to eql('val1')
316
+ expect(test_result['enum_test']).to be_an_instance_of(String)
317
+ expect(test_result['enum_test']).to eql('val1')
355
318
  end
356
319
 
357
320
  it "should raise an error given an invalid DATETIME" do
@@ -360,17 +323,14 @@ RSpec.describe Mysql2::Result do
360
323
  end
361
324
 
362
325
  context "string encoding for ENUM values" do
363
- before { pending('Encoding is undefined') unless defined?(Encoding) }
364
-
365
326
  it "should default to the connection's encoding if Encoding.default_internal is nil" do
366
327
  with_internal_encoding nil do
367
328
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
368
329
  expect(result['enum_test'].encoding).to eql(Encoding::UTF_8)
369
330
 
370
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
331
+ client2 = new_client(encoding: 'ascii')
371
332
  result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
372
333
  expect(result['enum_test'].encoding).to eql(Encoding::ASCII)
373
- client2.close
374
334
  end
375
335
  end
376
336
 
@@ -388,22 +348,19 @@ RSpec.describe Mysql2::Result do
388
348
  end
389
349
 
390
350
  it "should return String for a SET value" do
391
- expect(@test_result['set_test']).to be_an_instance_of(String)
392
- expect(@test_result['set_test']).to eql('val1,val2')
351
+ expect(test_result['set_test']).to be_an_instance_of(String)
352
+ expect(test_result['set_test']).to eql('val1,val2')
393
353
  end
394
354
 
395
355
  context "string encoding for SET values" do
396
- before { pending('Encoding is undefined') unless defined?(Encoding) }
397
-
398
356
  it "should default to the connection's encoding if Encoding.default_internal is nil" do
399
357
  with_internal_encoding nil do
400
358
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
401
359
  expect(result['set_test'].encoding).to eql(Encoding::UTF_8)
402
360
 
403
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
361
+ client2 = new_client(encoding: 'ascii')
404
362
  result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
405
363
  expect(result['set_test'].encoding).to eql(Encoding::ASCII)
406
- client2.close
407
364
  end
408
365
  end
409
366
 
@@ -421,13 +378,11 @@ RSpec.describe Mysql2::Result do
421
378
  end
422
379
 
423
380
  it "should return String for a BINARY value" do
424
- expect(@test_result['binary_test']).to be_an_instance_of(String)
425
- expect(@test_result['binary_test']).to eql("test#{"\000" * 6}")
381
+ expect(test_result['binary_test']).to be_an_instance_of(String)
382
+ expect(test_result['binary_test']).to eql("test#{"\000" * 6}")
426
383
  end
427
384
 
428
385
  context "string encoding for BINARY values" do
429
- before { pending('Encoding is undefined') unless defined?(Encoding) }
430
-
431
386
  it "should default to binary if Encoding.default_internal is nil" do
432
387
  with_internal_encoding nil do
433
388
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
@@ -462,14 +417,12 @@ RSpec.describe Mysql2::Result do
462
417
  'long_text_test' => 'LONGTEXT',
463
418
  }.each do |field, type|
464
419
  it "should return a String for #{type}" do
465
- expect(@test_result[field]).to be_an_instance_of(String)
466
- expect(@test_result[field]).to eql("test")
420
+ expect(test_result[field]).to be_an_instance_of(String)
421
+ expect(test_result[field]).to eql("test")
467
422
  end
468
423
 
469
424
  context "string encoding for #{type} values" do
470
- before { pending('Encoding is undefined') unless defined?(Encoding) }
471
-
472
- if %w(VARBINARY TINYBLOB BLOB MEDIUMBLOB LONGBLOB).include?(type)
425
+ if %w[VARBINARY TINYBLOB BLOB MEDIUMBLOB LONGBLOB].include?(type)
473
426
  it "should default to binary if Encoding.default_internal is nil" do
474
427
  with_internal_encoding nil do
475
428
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
@@ -494,10 +447,9 @@ RSpec.describe Mysql2::Result do
494
447
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
495
448
  expect(result[field].encoding).to eql(Encoding::UTF_8)
496
449
 
497
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
450
+ client2 = new_client(encoding: 'ascii')
498
451
  result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
499
452
  expect(result[field].encoding).to eql(Encoding::ASCII)
500
- client2.close
501
453
  end
502
454
  end
503
455
 
@@ -516,4 +468,18 @@ RSpec.describe Mysql2::Result do
516
468
  end
517
469
  end
518
470
  end
471
+
472
+ context "server flags" do
473
+ let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY null_test DESC LIMIT 1") }
474
+
475
+ it "should set a definitive value for query_was_slow" do
476
+ expect(test_result.server_flags[:query_was_slow]).to eql(false)
477
+ end
478
+ it "should set a definitive value for no_index_used" do
479
+ expect(test_result.server_flags[:no_index_used]).to eql(true)
480
+ end
481
+ it "should set a definitive value for no_good_index_used" do
482
+ expect(test_result.server_flags[:no_good_index_used]).to eql(false)
483
+ end
484
+ end
519
485
  end