aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/base_test.rb
diff options
context:
space:
mode:
authorEvan Light <evan@tripledogdare.net>2011-07-13 22:17:38 -0400
committerEvan Light <evan@tripledogdare.net>2011-07-14 14:04:02 -0400
commitf13dea8a3463b753a69c22fc27648160c013fc3b (patch)
tree0e7ec6af48a35a34a829ffdc9fe872d7139cca71 /activerecord/test/cases/base_test.rb
parent003c6516dcffcd846d1f257a16062cea657cbd33 (diff)
downloadrails-f13dea8a3463b753a69c22fc27648160c013fc3b.tar.gz
rails-f13dea8a3463b753a69c22fc27648160c013fc3b.tar.bz2
rails-f13dea8a3463b753a69c22fc27648160c013fc3b.zip
Fix and unit test for https://github.com/rails/rails/issues/2059
Cache key was incorrectly using timezone-dependent record#updated_at when it should be using a timezone-independent value to generate the cache key Minor refactoring to cache_key timezone test Closes #2059 Adds a test to validate the format of the cache_key for nil and present updated_at values Correctly handles updated_at == nil
Diffstat (limited to 'activerecord/test/cases/base_test.rb')
-rw-r--r--activerecord/test/cases/base_test.rb29
1 files changed, 27 insertions, 2 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 9feb7b010f..8144f7075d 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -488,11 +488,11 @@ class BasicsTest < ActiveRecord::TestCase
def test_hashing
assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ]
end
-
+
def test_comparison
topic_1 = Topic.create!
topic_2 = Topic.create!
-
+
assert_equal [topic_2, topic_1].sort, [topic_1, topic_2]
end
@@ -1835,4 +1835,29 @@ class BasicsTest < ActiveRecord::TestCase
def test_attribtue_names_on_abstract_class
assert_equal [], AbstractCompany.attribute_names
end
+
+ def test_cache_key_for_existing_record_is_not_timezone_dependent
+ ActiveRecord::Base.time_zone_aware_attributes = true
+
+ Time.zone = "UTC"
+ utc_key = Developer.first.cache_key
+
+ Time.zone = "EST"
+ est_key = Developer.first.cache_key
+
+ assert_equal utc_key, est_key
+ ensure
+ ActiveRecord::Base.time_zone_aware_attributes = false
+ end
+
+ def test_cache_key_format_for_existing_record_with_updated_at
+ dev = Developer.first
+ assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:number)}", dev.cache_key
+ end
+
+ def test_cache_key_format_for_existing_record_with_nil_updated_at
+ dev = Developer.first
+ dev.update_attribute(:updated_at, nil)
+ assert_match /\/#{dev.id}$/, dev.cache_key
+ end
end