diff options
author | Andrew White <andrew.white@unboxed.co> | 2018-03-11 18:30:19 +0000 |
---|---|---|
committer | Andrew White <andrew.white@unboxed.co> | 2018-03-11 18:30:19 +0000 |
commit | 7c479cbf6211d7efadc0a9573cf82c05291f7ef1 (patch) | |
tree | 01b4fed3ccf05af042af1af1f91f71730ec55a5e /activerecord/test/cases | |
parent | 3f95054f1c5ffe9e9b3bccdabc1ab1a7a4beb24a (diff) | |
download | rails-7c479cbf6211d7efadc0a9573cf82c05291f7ef1.tar.gz rails-7c479cbf6211d7efadc0a9573cf82c05291f7ef1.tar.bz2 rails-7c479cbf6211d7efadc0a9573cf82c05291f7ef1.zip |
Ensure that leading date is stripped by quoted_time
In #24542, quoted_time was introduced to strip the leading date
component for time columns because it was having a significant
effect in mariadb. However, it assumed that the date component
was always 2000-01-01 which isn't the case, especially if the
source wasn't another time column.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/quoting_test.rb | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb index 6534770c57..a8eed2ff26 100644 --- a/activerecord/test/cases/quoting_test.rb +++ b/activerecord/test/cases/quoting_test.rb @@ -46,27 +46,60 @@ module ActiveRecord assert_equal t.to_s(:db), @quoter.quoted_date(t) end - def test_quoted_time_utc + def test_quoted_timestamp_utc with_timezone_config default: :utc do t = Time.now.change(usec: 0) assert_equal t.getutc.to_s(:db), @quoter.quoted_date(t) end end - def test_quoted_time_local + def test_quoted_timestamp_local with_timezone_config default: :local do t = Time.now.change(usec: 0) assert_equal t.getlocal.to_s(:db), @quoter.quoted_date(t) end end - def test_quoted_time_crazy + def test_quoted_timestamp_crazy with_timezone_config default: :asdfasdf do t = Time.now.change(usec: 0) assert_equal t.getlocal.to_s(:db), @quoter.quoted_date(t) end end + def test_quoted_time_utc + with_timezone_config default: :utc do + t = Time.now.change(usec: 0) + + expected = t.change(year: 2000, month: 1, day: 1) + expected = expected.getutc.to_s(:db).sub("2000-01-01 ", "") + + assert_equal expected, @quoter.quoted_time(t) + end + end + + def test_quoted_time_local + with_timezone_config default: :local do + t = Time.now.change(usec: 0) + + expected = t.change(year: 2000, month: 1, day: 1) + expected = expected.getlocal.to_s(:db).sub("2000-01-01 ", "") + + assert_equal expected, @quoter.quoted_time(t) + end + end + + def test_quoted_time_crazy + with_timezone_config default: :asdfasdf do + t = Time.now.change(usec: 0) + + expected = t.change(year: 2000, month: 1, day: 1) + expected = expected.getlocal.to_s(:db).sub("2000-01-01 ", "") + + assert_equal expected, @quoter.quoted_time(t) + end + end + def test_quoted_datetime_utc with_timezone_config default: :utc do t = Time.now.change(usec: 0).to_datetime |