Skip to content
This repository
Browse code

Merge pull request #2063 from elight/master

Patch for #2059
  • Loading branch information...
commit 31ea0276a4f6059799ec031757caf2511d9c90c5 2 parents d632e92 + f13dea8
Santiago Pastorino spastorino authored
3  activerecord/lib/active_record/base.rb
@@ -1638,7 +1638,8 @@ def cache_key
1638 1638 when new_record?
1639 1639 "#{self.class.model_name.cache_key}/new"
1640 1640 when timestamp = self[:updated_at]
1641   - "#{self.class.model_name.cache_key}/#{id}-#{timestamp.to_s(:number)}"
  1641 + timestamp = timestamp.utc.to_s(:number)
  1642 + "#{self.class.model_name.cache_key}/#{id}-#{timestamp}"
1642 1643 else
1643 1644 "#{self.class.model_name.cache_key}/#{id}"
1644 1645 end
29 activerecord/test/cases/base_test.rb
@@ -488,11 +488,11 @@ def test_equality_of_destroyed_records
488 488 def test_hashing
489 489 assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ]
490 490 end
491   -
  491 +
492 492 def test_comparison
493 493 topic_1 = Topic.create!
494 494 topic_2 = Topic.create!
495   -
  495 +
496 496 assert_equal [topic_2, topic_1].sort, [topic_1, topic_2]
497 497 end
498 498
@@ -1835,4 +1835,29 @@ def test_attribute_names_on_table_not_exists
1835 1835 def test_attribtue_names_on_abstract_class
1836 1836 assert_equal [], AbstractCompany.attribute_names
1837 1837 end
  1838 +
  1839 + def test_cache_key_for_existing_record_is_not_timezone_dependent
  1840 + ActiveRecord::Base.time_zone_aware_attributes = true
  1841 +
  1842 + Time.zone = "UTC"
  1843 + utc_key = Developer.first.cache_key
  1844 +
  1845 + Time.zone = "EST"
  1846 + est_key = Developer.first.cache_key
  1847 +
  1848 + assert_equal utc_key, est_key
  1849 + ensure
  1850 + ActiveRecord::Base.time_zone_aware_attributes = false
  1851 + end
  1852 +
  1853 + def test_cache_key_format_for_existing_record_with_updated_at
  1854 + dev = Developer.first
  1855 + assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:number)}", dev.cache_key
  1856 + end
  1857 +
  1858 + def test_cache_key_format_for_existing_record_with_nil_updated_at
  1859 + dev = Developer.first
  1860 + dev.update_attribute(:updated_at, nil)
  1861 + assert_match /\/#{dev.id}$/, dev.cache_key
  1862 + end
1838 1863 end

0 comments on commit 31ea027

Please sign in to comment.
Something went wrong with that request. Please try again.