1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/cache_key_test.rb
Maarten Jacobs 86d2924a11 fixes #21815
The default timestamp used for AR is `updated_at` in nanoseconds! (:nsec) This causes issues on any machine that runs an OS that supports nanoseconds timestamps, i.e. not-OS X, where the cache_key of the record persisted in the database (milliseconds precision) is out-of-sync with the cache_key in the ruby VM.

This commit adds:

A test that shows the issue, it can be found in the separate file `cache_key_test.rb`, because
- model couldn't be defined inline
- transactional testing needed to be turned off to get it to pass the MySQL tests
This seemed cleaner than putting it in an existing testcase file.

It adds :usec as a dateformat that calculates datetime in microseconds

It sets precision of cache_key to :usec instead of :nsec, as no db supports nsec precision on timestamps
2015-10-16 15:09:45 +02:00

25 lines
576 B
Ruby

require "cases/helper"
module ActiveRecord
class CacheKeyTest < ActiveRecord::TestCase
self.use_transactional_tests = false
class CacheMe < ActiveRecord::Base; end
setup do
@connection = ActiveRecord::Base.connection
@connection.create_table(:cache_mes) { |t| t.timestamps }
end
teardown do
@connection.drop_table :cache_mes, if_exists: true
end
test "test_cache_key_format_is_not_too_precise" do
record = CacheMe.create
key = record.cache_key
assert_equal key, record.reload.cache_key
end
end
end