Permalink
Browse files

refactor the checking of the attributes of the record in IdentityMap#…

…add, so it's more readable
  • Loading branch information...
1 parent a00a42d commit 15a2e0dee2d6bd3dcc7eb47ff1a28a9c7433be38 @arturopie committed Mar 27, 2012
Showing with 12 additions and 5 deletions.
  1. +7 −1 activerecord/lib/active_record/identity_map.rb
  2. +5 −4 activerecord/test/cases/identity_map_test.rb
@@ -90,7 +90,7 @@ def get(klass, primary_key)
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 @@ def remove_by_id(symbolized_sti_name, id)
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+.
@@ -404,11 +404,12 @@ def test_find_using_identity_map_respects_readonly
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

0 comments on commit 15a2e0d

Please sign in to comment.