|
208 | 208 | expect(@test_result['tiny_int_test']).to eql(1)
|
209 | 209 | end
|
210 | 210 |
|
211 |
| - it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do |
212 |
| - @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (1)' |
213 |
| - id1 = @client.last_id |
214 |
| - @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (0)' |
215 |
| - id2 = @client.last_id |
216 |
| - @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)' |
217 |
| - id3 = @client.last_id |
218 |
| - |
219 |
| - result1 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast_booleans => true |
220 |
| - result2 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1', :cast_booleans => true |
221 |
| - result3 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = -1 LIMIT 1', :cast_booleans => true |
222 |
| - expect(result1.first['bool_cast_test']).to be true |
223 |
| - expect(result2.first['bool_cast_test']).to be false |
224 |
| - expect(result3.first['bool_cast_test']).to be true |
| 211 | + context "cast booleans for TINYINT if :cast_booleans is enabled" do |
| 212 | + # rubocop:disable Style/Semicolon |
| 213 | + let(:id1) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 1)'; @client.last_id } |
| 214 | + let(:id2) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 0)'; @client.last_id } |
| 215 | + let(:id3) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'; @client.last_id } |
| 216 | + # rubocop:enable Style/Semicolon |
| 217 | + |
| 218 | + after do |
| 219 | + @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})" |
| 220 | + end |
225 | 221 |
|
226 |
| - @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})" |
| 222 | + 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 |
| 226 | + expect(result1.first['bool_cast_test']).to be true |
| 227 | + expect(result2.first['bool_cast_test']).to be false |
| 228 | + expect(result3.first['bool_cast_test']).to be true |
| 229 | + end |
227 | 230 | end
|
228 | 231 |
|
229 |
| - it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do |
230 |
| - @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)' |
231 |
| - id1 = @client.last_id |
232 |
| - @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)' |
233 |
| - id2 = @client.last_id |
| 232 | + context "cast booleans for BIT(1) if :cast_booleans is enabled" do |
| 233 | + # rubocop:disable Style/Semicolon |
| 234 | + let(:id1) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'; @client.last_id } |
| 235 | + let(:id2) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'; @client.last_id } |
| 236 | + # rubocop:enable Style/Semicolon |
234 | 237 |
|
235 |
| - result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", :cast_booleans => true |
236 |
| - result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", :cast_booleans => true |
237 |
| - expect(result1.first['single_bit_test']).to be true |
238 |
| - expect(result2.first['single_bit_test']).to be false |
| 238 | + after do |
| 239 | + @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})" |
| 240 | + end |
239 | 241 |
|
240 |
| - @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})" |
| 242 | + 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 |
| 245 | + expect(result1.first['single_bit_test']).to be true |
| 246 | + expect(result2.first['single_bit_test']).to be false |
| 247 | + end |
241 | 248 | end
|
242 | 249 |
|
243 | 250 | it "should return Fixnum for a SMALLINT value" do
|
|
285 | 292 | expect(@test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
|
286 | 293 | end
|
287 | 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 |
| 305 | + end |
| 306 | + |
| 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 |
| 317 | + end |
| 318 | + |
288 | 319 | if 1.size == 4 # 32bit
|
289 | 320 | klass = if RUBY_VERSION =~ /1.8/
|
290 | 321 | DateTime
|
|
0 commit comments