diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2015-02-01 13:02:56 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2015-02-08 22:22:55 +0900 |
commit | f9839120379292cbc5da25f35311f457b08b44a8 (patch) | |
tree | 32d780f568088bbfa3519a0f8ca23137ca7d533a /activerecord/test/cases | |
parent | 31fafe0a3223b58e214c03c88a33d6ef4435f63c (diff) | |
download | rails-f9839120379292cbc5da25f35311f457b08b44a8.tar.gz rails-f9839120379292cbc5da25f35311f457b08b44a8.tar.bz2 rails-f9839120379292cbc5da25f35311f457b08b44a8.zip |
Fix rounding problem for PostgreSQL timestamp column
If timestamp column have the precision, it need to format according to
the precision of timestamp column.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/timestamp_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/timestamp_test.rb b/activerecord/test/cases/adapters/postgresql/timestamp_test.rb index eb32c4d2c2..8246b14b93 100644 --- a/activerecord/test/cases/adapters/postgresql/timestamp_test.rb +++ b/activerecord/test/cases/adapters/postgresql/timestamp_test.rb @@ -46,6 +46,8 @@ end class TimestampTest < ActiveRecord::TestCase fixtures :topics + class Foo < ActiveRecord::Base; end + def test_group_by_date keys = Topic.group("date_trunc('month', created_at)").count.keys assert_operator keys.length, :>, 0 @@ -135,6 +137,20 @@ class TimestampTest < ActiveRecord::TestCase assert_equal date, Developer.find_by_name("yahagi").updated_at end + def test_formatting_timestamp_according_to_precision + ActiveRecord::Base.connection.create_table(:foos, force: true) do |t| + t.datetime :created_at, precision: 0 + t.datetime :updated_at, precision: 4 + end + date = ::Time.utc(2014, 8, 17, 12, 30, 0, 999999) + Foo.create!(created_at: date, updated_at: date) + assert foo = Foo.find_by(created_at: date) + assert_equal date.to_s, foo.created_at.to_s + assert_equal date.to_s, foo.updated_at.to_s + assert_equal 000000, foo.created_at.usec + assert_equal 999900, foo.updated_at.usec + end + private def pg_datetime_precision(table_name, column_name) |