aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/type
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2015-09-22 12:48:50 +0300
committerBogdan Gusiev <agresso@gmail.com>2015-09-23 13:29:08 +0300
commitd03f5196657bf466d7576cd6cbd4886db030723b (patch)
tree29b1c6b120ebe89878905c0b112892d5300f6585 /activerecord/test/cases/type
parent8842ce239562d3fbc82198ac3c4618935134ff39 (diff)
downloadrails-d03f5196657bf466d7576cd6cbd4886db030723b.tar.gz
rails-d03f5196657bf466d7576cd6cbd4886db030723b.tar.bz2
rails-d03f5196657bf466d7576cd6cbd4886db030723b.zip
Fixed taking precision into count when assigning a value to timestamp attribute
Timestamp column can have less precision than ruby timestamp In result in how big a fraction of a second can be stored in the database. m = Model.create! m.created_at.usec == m.reload.created_at.usec # => false # due to different seconds precision in Time.now and database column If the precision is low enough, (mysql default is 0, so it is always low enough by default) the value changes when model is reloaded from the database. This patch fixes that issue ensuring that any timestamp assigned as an attribute is converted to column precision under the attribute.
Diffstat (limited to 'activerecord/test/cases/type')
-rw-r--r--activerecord/test/cases/type/date_time_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/type/date_time_test.rb b/activerecord/test/cases/type/date_time_test.rb
new file mode 100644
index 0000000000..62d3405be1
--- /dev/null
+++ b/activerecord/test/cases/type/date_time_test.rb
@@ -0,0 +1,13 @@
+require "cases/helper"
+require "models/task"
+
+module ActiveRecord
+ module Type
+ class IntegerTest < ActiveRecord::TestCase
+ def test_datetime_seconds_precision_applied_to_timestamp
+ p = Task.create!(starting: ::Time.now)
+ assert_equal p.starting.usec, p.reload.starting.usec
+ end
+ end
+ end
+end