aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorArturo Pie <arturotd08@yahoo.ca>2012-03-26 22:45:48 -0400
committerArturo Pie <arturotd08@yahoo.ca>2012-03-29 22:24:15 -0400
commit714a2c810deb9d219442f7c981e61eb6d5c45d33 (patch)
treeea9da2e56283d4c79bfc58d2c2edf8e8a757c529 /activerecord
parent2c8f84d3a6b199b04394ed1a5bba3bc0d8f1e811 (diff)
downloadrails-714a2c810deb9d219442f7c981e61eb6d5c45d33.tar.gz
rails-714a2c810deb9d219442f7c981e61eb6d5c45d33.tar.bz2
rails-714a2c810deb9d219442f7c981e61eb6d5c45d33.zip
refactor the checking of the attributes of the record in IdentityMap#add, so it's more readable
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/identity_map.rb8
-rw-r--r--activerecord/test/cases/identity_map_test.rb9
2 files changed, 12 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/identity_map.rb b/activerecord/lib/active_record/identity_map.rb
index 7ff755110f..f3891b406e 100644
--- a/activerecord/lib/active_record/identity_map.rb
+++ b/activerecord/lib/active_record/identity_map.rb
@@ -90,7 +90,7 @@ module ActiveRecord
end
def add(record)
- repository[record.class.symbolized_sti_name][record.id] = record if record.class.column_names - record.attribute_names == []
+ repository[record.class.symbolized_sti_name][record.id] = record if contain_all_columns(record)
end
def remove(record)
@@ -104,6 +104,12 @@ module ActiveRecord
def clear
repository.clear
end
+
+ private
+
+ def contain_all_columns(record)
+ (record.class.column_names - record.attribute_names) == []
+ end
end
# Reinitialize an Identity Map model object from +coder+.
diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb
index 2a490126e2..63d0bcf1fc 100644
--- a/activerecord/test/cases/identity_map_test.rb
+++ b/activerecord/test/cases/identity_map_test.rb
@@ -404,11 +404,12 @@ class IdentityMapTest < ActiveRecord::TestCase
assert comment.save
end
- def test_do_not_add_to_identity_map_if_record_do_not_contain_all_columns
- post = Post.select(:id).first
- comment = post.comments[0]
+ def test_do_not_add_to_repository_if_record_does_not_contain_all_columns
+ author = Author.select(:id).first
+ post = author.posts.first
+
assert_nothing_raised do
- assert_not_nil comment.post.title
+ assert_not_nil post.author.name
end
end