Merge pull request #2065 from elight/3-1-stable

Backport of cache_key fix from master
This commit is contained in:
Santiago Pastorino
2011-07-16 06:06:33 -07:00
2 changed files with 29 additions and 3 deletions

View File

@@ -1639,7 +1639,8 @@ MSG
when new_record?
"#{self.class.model_name.cache_key}/new"
when timestamp = self[:updated_at]
"#{self.class.model_name.cache_key}/#{id}-#{timestamp.to_s(:number)}"
timestamp = timestamp.utc.to_s(:number)
"#{self.class.model_name.cache_key}/#{id}-#{timestamp}"
else
"#{self.class.model_name.cache_key}/#{id}"
end

View File

@@ -478,11 +478,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
@@ -1832,4 +1832,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