aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-08-30 14:09:16 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-09-09 14:37:57 -0700
commit4b7b8d9e19b662d8a1135fec73b422202f97472a (patch)
treec747270b5ec551f6d96eb7e47da71b2bb389ae34 /activerecord/test/cases/attribute_methods_test.rb
parentcc81b04ae540c0b75f5428951e11dea2f13a0946 (diff)
downloadrails-4b7b8d9e19b662d8a1135fec73b422202f97472a.tar.gz
rails-4b7b8d9e19b662d8a1135fec73b422202f97472a.tar.bz2
rails-4b7b8d9e19b662d8a1135fec73b422202f97472a.zip
Cache unserialized attributes
Diffstat (limited to 'activerecord/test/cases/attribute_methods_test.rb')
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 9b3cc47c79..3c4fa4fd3f 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -419,12 +419,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase
Topic.instance_variable_set "@cached_attributes", nil
end
- def test_time_related_columns_are_actually_cached
- column_types = %w(datetime timestamp time date).map(&:to_sym)
- column_names = Topic.columns.select{|c| column_types.include?(c.type) }.map(&:name)
-
- assert_equal column_names.sort, Topic.cached_attributes.sort
- assert_equal time_related_columns_on_topic.sort, Topic.cached_attributes.sort
+ def test_cacheable_columns_are_actually_cached
+ assert_equal cached_columns.sort, Topic.cached_attributes.sort
end
def test_accessing_cached_attributes_caches_the_converted_values_and_nothing_else
@@ -435,8 +431,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert cache.empty?
all_columns = Topic.columns.map(&:name)
- cached_columns = time_related_columns_on_topic
- uncached_columns = all_columns - cached_columns
+ uncached_columns = all_columns - cached_columns
all_columns.each do |attr_name|
attribute_gets_cached = Topic.cache_attribute?(attr_name)
@@ -594,8 +589,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase
private
+ def cached_columns
+ @cached_columns ||= (time_related_columns_on_topic + serialized_columns_on_topic).map(&:name)
+ end
+
def time_related_columns_on_topic
- Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name)
+ Topic.columns.select { |c| [:time, :date, :datetime, :timestamp].include?(c.type) }
+ end
+
+ def serialized_columns_on_topic
+ Topic.columns.select { |c| Topic.serialized_attributes.include?(c.name) }
end
def in_time_zone(zone)