提交 454ec93f 编写于 作者: E Emilio Tagua 提交者: José Valim

Add log message when loading records from Identity Map.

Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 b3561723
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册