Skip to content
Browse files

Add log message when loading records from Identity Map.

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent b356172 commit 454ec93ff79af4c0ddb31d01827021b549d12413 @miloops miloops committed with josevalim Apr 3, 2011
Showing with 17 additions and 1 deletion.
  1. +8 −1 activerecord/lib/active_record/identity_map.rb
  2. +9 −0 activerecord/test/cases/identity_map_test.rb
View
9 activerecord/lib/active_record/identity_map.rb
@@ -50,7 +50,14 @@ def without
def get(klass, primary_key)
obj = repository[klass.symbolized_base_class][primary_key]
- obj.is_a?(klass) ? obj : nil
+ if obj.is_a?(klass)
+ if ActiveRecord::Base.logger
+ ActiveRecord::Base.logger.debug "#{klass} with ID = #{primary_key} loaded from Identity Map"
+ end
+ obj
+ else
+ nil
+ end
end
def add(record)
View
9 activerecord/test/cases/identity_map_test.rb
@@ -388,6 +388,15 @@ def test_find_using_select_and_identity_map
assert_not_nil post.title
end
+ def test_log
+ log = StringIO.new
+ ActiveRecord::Base.logger = Logger.new(log)
+ ActiveRecord::Base.logger.level = Logger::DEBUG
+ Post.find 1
+ Post.find 1
+ assert_match(/Post with ID = 1 loaded from Identity Map/, log.string)
+ end
+
# Currently AR is not allowing changing primary key (see Persistence#update)
# So we ignore it. If this changes, this test needs to be uncommented.
# def test_updating_of_pkey

0 comments on commit 454ec93

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