From 1dc98c143c4bf84ccfb55b30c7d41b29b62d50cf Mon Sep 17 00:00:00 2001 From: Brendon Murphy Date: Wed, 23 Jan 2013 01:47:23 -0800 Subject: cache_key consults updated_on timestamp if present - Extract max timestamp retrieval for cache_key - Update changelog for cache_key changes --- activerecord/test/cases/base_test.rb | 22 ++++++++++++++++++++-- activerecord/test/schema/schema.rb | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index af1845c937..5d558d5093 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1441,12 +1441,30 @@ class BasicsTest < ActiveRecord::TestCase assert_not_equal key, car.cache_key end - def test_cache_key_format_for_existing_record_with_nil_updated_at + def test_cache_key_format_for_existing_record_with_nil_updated_timestamps dev = Developer.first - dev.update_columns(updated_at: nil) + dev.update_columns(updated_at: nil, updated_on: nil) assert_match(/\/#{dev.id}$/, dev.cache_key) end + def test_cache_key_for_updated_on + dev = Developer.first + dev.updated_at = nil + assert_equal "developers/#{dev.id}-#{dev.updated_on.utc.to_s(:nsec)}", dev.cache_key + end + + def test_cache_key_for_newer_updated_at + dev = Developer.first + dev.updated_at += 3600 + assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:nsec)}", dev.cache_key + end + + def test_cache_key_for_newer_updated_on + dev = Developer.first + dev.updated_on += 3600 + assert_equal "developers/#{dev.id}-#{dev.updated_on.utc.to_s(:nsec)}", dev.cache_key + end + def test_touch_should_raise_error_on_a_new_object company = Company.new(:rating => 1, :name => "37signals", :firm_name => "37signals") assert_raises(ActiveRecord::ActiveRecordError) do diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index d789b6cb7a..a323b1e722 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -219,6 +219,8 @@ ActiveRecord::Schema.define do t.integer :salary, :default => 70000 t.datetime :created_at t.datetime :updated_at + t.datetime :created_on + t.datetime :updated_on end create_table :developers_projects, :force => true, :id => false do |t| -- cgit v1.2.3