Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…add, so it's more readable
  • Loading branch information...
commit 714a2c810deb9d219442f7c981e61eb6d5c45d33 1 parent 2c8f84d
@arturopie arturopie authored
View
8 activerecord/lib/active_record/identity_map.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+.
View
9 activerecord/test/cases/identity_map_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.