diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2015-02-13 03:04:47 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2015-02-20 10:25:31 +0900 |
commit | a088ee96918a938159cbeee1a3fe822f0bb46b5d (patch) | |
tree | 9b09d02933d2bc2cbed740e9daa1cc68ccad328a /activerecord/test | |
parent | 9ef870c0426f573355a10b04fd9740550492cd00 (diff) | |
download | rails-a088ee96918a938159cbeee1a3fe822f0bb46b5d.tar.gz rails-a088ee96918a938159cbeee1a3fe822f0bb46b5d.tar.bz2 rails-a088ee96918a938159cbeee1a3fe822f0bb46b5d.zip |
Format the time string according to the precision of the time column
It is also necessary to format a time column like a datetime column.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/time_precision_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/time_precision_test.rb b/activerecord/test/cases/time_precision_test.rb index 23422fd50a..c3fb275936 100644 --- a/activerecord/test/cases/time_precision_test.rb +++ b/activerecord/test/cases/time_precision_test.rb @@ -2,6 +2,10 @@ require 'cases/helper' if ActiveRecord::Base.connection.supports_datetime_with_precision? class TimePrecisionTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + class Foo < ActiveRecord::Base; end + setup do @connection = ActiveRecord::Base.connection end @@ -45,6 +49,21 @@ class TimePrecisionTest < ActiveRecord::TestCase assert_equal 4, database_datetime_precision('foos', 'finish') end + def test_formatting_time_according_to_precision + @connection.create_table(:foos, force: true) do |t| + t.time :start, precision: 0 + t.time :finish, precision: 4 + end + time = ::Time.utc(2000, 1, 1, 12, 30, 0, 999999) + Foo.create!(start: time, finish: time) + assert foo = Foo.find_by(start: time) + assert_equal 1, Foo.where(finish: time).count + assert_equal time.to_s, foo.start.to_s + assert_equal time.to_s, foo.finish.to_s + assert_equal 000000, foo.start.usec + assert_equal 999900, foo.finish.usec + end + private def database_datetime_precision(table_name, column_name) |