mysql2 0.4.10 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  RSpec.describe Mysql2::Error do
@@ -42,8 +40,6 @@ RSpec.describe Mysql2::Error do
42
40
  end
43
41
 
44
42
  before do
45
- pending('String#encoding is not defined') unless String.public_method_defined?(:encoding)
46
-
47
43
  # sanity check
48
44
  expect(valid_utf8.encoding).to eql(Encoding::UTF_8)
49
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,13 +137,13 @@ 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)
@@ -162,24 +159,22 @@ RSpec.describe Mysql2::Result do
162
159
  end
163
160
 
164
161
  @client.query "SET net_write_timeout = 1"
165
- res = @client.query "SELECT * FROM streamingTest", :stream => true, :cache_rows => false
162
+ res = @client.query "SELECT * FROM streamingTest", stream: true, cache_rows: false
166
163
 
167
- expect {
164
+ expect do
168
165
  res.each_with_index do |_, i|
169
166
  # Exhaust the first result packet then trigger a timeout
170
167
  sleep 2 if i > 0 && i % 1000 == 0
171
168
  end
172
- }.to raise_error(Mysql2::Error, /Lost connection/)
169
+ end.to raise_error(Mysql2::Error, /Lost connection/)
173
170
  end
174
171
  end
175
172
 
176
173
  context "row data type mapping" do
177
- before(:each) do
178
- @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
179
- end
174
+ let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first }
180
175
 
181
176
  it "should return nil values for NULL and strings for everything else when :cast is false" do
182
- 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
183
178
  expect(result["null_test"]).to be_nil
184
179
  expect(result["tiny_int_test"]).to eql("1")
185
180
  expect(result["bool_cast_test"]).to eql("1")
@@ -189,23 +184,23 @@ RSpec.describe Mysql2::Result do
189
184
  end
190
185
 
191
186
  it "should return nil for a NULL value" do
192
- expect(@test_result['null_test']).to be_an_instance_of(NilClass)
193
- 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)
194
189
  end
195
190
 
196
191
  it "should return String for a BIT(64) value" do
197
- expect(@test_result['bit_test']).to be_an_instance_of(String)
198
- 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")
199
194
  end
200
195
 
201
196
  it "should return String for a BIT(1) value" do
202
- expect(@test_result['single_bit_test']).to be_an_instance_of(String)
203
- 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")
204
199
  end
205
200
 
206
201
  it "should return Fixnum for a TINYINT value" do
207
- expect([Fixnum, Bignum]).to include(@test_result['tiny_int_test'].class)
208
- 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)
209
204
  end
210
205
 
211
206
  context "cast booleans for TINYINT if :cast_booleans is enabled" do
@@ -220,9 +215,9 @@ RSpec.describe Mysql2::Result do
220
215
  end
221
216
 
222
217
  it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
223
- result1 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id1} LIMIT 1", :cast_booleans => true
224
- result2 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id2} LIMIT 1", :cast_booleans => true
225
- result3 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id3} LIMIT 1", :cast_booleans => true
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
226
221
  expect(result1.first['bool_cast_test']).to be true
227
222
  expect(result2.first['bool_cast_test']).to be false
228
223
  expect(result3.first['bool_cast_test']).to be true
@@ -240,147 +235,86 @@ RSpec.describe Mysql2::Result do
240
235
  end
241
236
 
242
237
  it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
243
- result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", :cast_booleans => true
244
- result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", :cast_booleans => true
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
245
240
  expect(result1.first['single_bit_test']).to be true
246
241
  expect(result2.first['single_bit_test']).to be false
247
242
  end
248
243
  end
249
244
 
250
245
  it "should return Fixnum for a SMALLINT value" do
251
- expect([Fixnum, Bignum]).to include(@test_result['small_int_test'].class)
252
- 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)
253
248
  end
254
249
 
255
250
  it "should return Fixnum for a MEDIUMINT value" do
256
- expect([Fixnum, Bignum]).to include(@test_result['medium_int_test'].class)
257
- 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)
258
253
  end
259
254
 
260
255
  it "should return Fixnum for an INT value" do
261
- expect([Fixnum, Bignum]).to include(@test_result['int_test'].class)
262
- 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)
263
258
  end
264
259
 
265
260
  it "should return Fixnum for a BIGINT value" do
266
- expect([Fixnum, Bignum]).to include(@test_result['big_int_test'].class)
267
- 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)
268
263
  end
269
264
 
270
265
  it "should return Fixnum for a YEAR value" do
271
- expect([Fixnum, Bignum]).to include(@test_result['year_test'].class)
272
- 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)
273
268
  end
274
269
 
275
270
  it "should return BigDecimal for a DECIMAL value" do
276
- expect(@test_result['decimal_test']).to be_an_instance_of(BigDecimal)
277
- 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)
278
273
  end
279
274
 
280
275
  it "should return Float for a FLOAT value" do
281
- expect(@test_result['float_test']).to be_an_instance_of(Float)
282
- 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)
283
278
  end
284
279
 
285
280
  it "should return Float for a DOUBLE value" do
286
- expect(@test_result['double_test']).to be_an_instance_of(Float)
287
- 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)
288
283
  end
289
284
 
290
285
  it "should return Time for a DATETIME value when within the supported range" do
291
- expect(@test_result['date_time_test']).to be_an_instance_of(Time)
292
- expect(@test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
293
- end
294
-
295
- it "should return Time values with microseconds" do
296
- now = Time.now
297
- if RUBY_VERSION =~ /1.8/ || @client.server_info[:id] / 100 < 506
298
- result = @client.query("SELECT CAST('#{now.strftime('%F %T %z')}' AS DATETIME) AS a")
299
- expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z'))
300
- else
301
- result = @client.query("SELECT CAST('#{now.strftime('%F %T.%6N %z')}' AS DATETIME(6)) AS a")
302
- # microseconds is 6 digits after the decimal, but only test on 5 significant figures
303
- expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
304
- end
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')
305
288
  end
306
289
 
307
- it "should return DateTime values with microseconds" do
308
- now = DateTime.now
309
- if RUBY_VERSION =~ /1.8/ || @client.server_info[:id] / 100 < 506
310
- result = @client.query("SELECT CAST('#{now.strftime('%F %T %z')}' AS DATETIME) AS a")
311
- expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z'))
312
- else
313
- result = @client.query("SELECT CAST('#{now.strftime('%F %T.%6N %z')}' AS DATETIME(6)) AS a")
314
- # microseconds is 6 digits after the decimal, but only test on 5 significant figures
315
- expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
316
- 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)
317
293
  end
318
294
 
319
- if 1.size == 4 # 32bit
320
- klass = if RUBY_VERSION =~ /1.8/
321
- DateTime
322
- else
323
- Time
324
- end
325
-
326
- it "should return DateTime when timestamp is < 1901-12-13 20:45:52" do
327
- # 1901-12-13T20:45:52 is the min for 32bit Ruby 1.8
328
- r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
329
- expect(r.first['test']).to be_an_instance_of(klass)
330
- end
331
-
332
- it "should return DateTime when timestamp is > 2038-01-19T03:14:07" do
333
- # 2038-01-19T03:14:07 is the max for 32bit Ruby 1.8
334
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
335
- expect(r.first['test']).to be_an_instance_of(klass)
336
- end
337
- elsif 1.size == 8 # 64bit
338
- if RUBY_VERSION =~ /1.8/
339
- it "should return Time when timestamp is > 0138-12-31 11:59:59" do
340
- r = @client.query("SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test")
341
- expect(r.first['test']).to be_an_instance_of(Time)
342
- end
343
-
344
- it "should return DateTime when timestamp is < 0139-1-1T00:00:00" do
345
- r = @client.query("SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test")
346
- expect(r.first['test']).to be_an_instance_of(DateTime)
347
- end
348
-
349
- it "should return Time when timestamp is > 2038-01-19T03:14:07" do
350
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
351
- expect(r.first['test']).to be_an_instance_of(Time)
352
- end
353
- else
354
- it "should return Time when timestamp is < 1901-12-13 20:45:52" do
355
- r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
356
- expect(r.first['test']).to be_an_instance_of(Time)
357
- end
358
-
359
- it "should return Time when timestamp is > 2038-01-19T03:14:07" do
360
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
361
- expect(r.first['test']).to be_an_instance_of(Time)
362
- end
363
- 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)
364
298
  end
365
299
 
366
300
  it "should return Time for a TIMESTAMP value when within the supported range" do
367
- expect(@test_result['timestamp_test']).to be_an_instance_of(Time)
368
- 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')
369
303
  end
370
304
 
371
305
  it "should return Time for a TIME value" do
372
- expect(@test_result['time_test']).to be_an_instance_of(Time)
373
- 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')
374
308
  end
375
309
 
376
310
  it "should return Date for a DATE value" do
377
- expect(@test_result['date_test']).to be_an_instance_of(Date)
378
- 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')
379
313
  end
380
314
 
381
315
  it "should return String for an ENUM value" do
382
- expect(@test_result['enum_test']).to be_an_instance_of(String)
383
- 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')
384
318
  end
385
319
 
386
320
  it "should raise an error given an invalid DATETIME" do
@@ -389,14 +323,12 @@ RSpec.describe Mysql2::Result do
389
323
  end
390
324
 
391
325
  context "string encoding for ENUM values" do
392
- before { pending('Encoding is undefined') unless defined?(Encoding) }
393
-
394
326
  it "should default to the connection's encoding if Encoding.default_internal is nil" do
395
327
  with_internal_encoding nil do
396
328
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
397
329
  expect(result['enum_test'].encoding).to eql(Encoding::UTF_8)
398
330
 
399
- client2 = new_client(:encoding => 'ascii')
331
+ client2 = new_client(encoding: 'ascii')
400
332
  result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
401
333
  expect(result['enum_test'].encoding).to eql(Encoding::ASCII)
402
334
  end
@@ -416,19 +348,17 @@ RSpec.describe Mysql2::Result do
416
348
  end
417
349
 
418
350
  it "should return String for a SET value" do
419
- expect(@test_result['set_test']).to be_an_instance_of(String)
420
- 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')
421
353
  end
422
354
 
423
355
  context "string encoding for SET values" do
424
- before { pending('Encoding is undefined') unless defined?(Encoding) }
425
-
426
356
  it "should default to the connection's encoding if Encoding.default_internal is nil" do
427
357
  with_internal_encoding nil do
428
358
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
429
359
  expect(result['set_test'].encoding).to eql(Encoding::UTF_8)
430
360
 
431
- client2 = new_client(:encoding => 'ascii')
361
+ client2 = new_client(encoding: 'ascii')
432
362
  result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
433
363
  expect(result['set_test'].encoding).to eql(Encoding::ASCII)
434
364
  end
@@ -448,13 +378,11 @@ RSpec.describe Mysql2::Result do
448
378
  end
449
379
 
450
380
  it "should return String for a BINARY value" do
451
- expect(@test_result['binary_test']).to be_an_instance_of(String)
452
- 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}")
453
383
  end
454
384
 
455
385
  context "string encoding for BINARY values" do
456
- before { pending('Encoding is undefined') unless defined?(Encoding) }
457
-
458
386
  it "should default to binary if Encoding.default_internal is nil" do
459
387
  with_internal_encoding nil do
460
388
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
@@ -489,14 +417,12 @@ RSpec.describe Mysql2::Result do
489
417
  'long_text_test' => 'LONGTEXT',
490
418
  }.each do |field, type|
491
419
  it "should return a String for #{type}" do
492
- expect(@test_result[field]).to be_an_instance_of(String)
493
- 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")
494
422
  end
495
423
 
496
424
  context "string encoding for #{type} values" do
497
- before { pending('Encoding is undefined') unless defined?(Encoding) }
498
-
499
- if %w(VARBINARY TINYBLOB BLOB MEDIUMBLOB LONGBLOB).include?(type)
425
+ if %w[VARBINARY TINYBLOB BLOB MEDIUMBLOB LONGBLOB].include?(type)
500
426
  it "should default to binary if Encoding.default_internal is nil" do
501
427
  with_internal_encoding nil do
502
428
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
@@ -521,7 +447,7 @@ RSpec.describe Mysql2::Result do
521
447
  result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
522
448
  expect(result[field].encoding).to eql(Encoding::UTF_8)
523
449
 
524
- client2 = new_client(:encoding => 'ascii')
450
+ client2 = new_client(encoding: 'ascii')
525
451
  result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
526
452
  expect(result[field].encoding).to eql(Encoding::ASCII)
527
453
  end
@@ -542,4 +468,18 @@ RSpec.describe Mysql2::Result do
542
468
  end
543
469
  end
544
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
545
485
  end