Fixed Stack level too deep error when calling #find_name_by_reflection for missing record.

git-svn-id: http://svn.redmine.org/redmine/trunk@14002 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2015-02-14 08:57:22 +00:00
parent efbbabe620
commit 3642626052
2 changed files with 7 additions and 3 deletions

View File

@@ -460,14 +460,14 @@ module IssuesHelper
end end
@detail_value_name_by_reflection ||= Hash.new do |hash, key| @detail_value_name_by_reflection ||= Hash.new do |hash, key|
association = Issue.reflect_on_association(key.first.to_sym) association = Issue.reflect_on_association(key.first.to_sym)
name = nil
if association if association
record = association.klass.find_by_id(key.last) record = association.klass.find_by_id(key.last)
if record if record
record.name.force_encoding('UTF-8') name = record.name.force_encoding('UTF-8')
hash[key] = record.name
end end
end end
hash[key] ||= nil hash[key] = name
end end
@detail_value_name_by_reflection[[field, id]] @detail_value_name_by_reflection[[field, id]]
end end

View File

@@ -295,4 +295,8 @@ class IssuesHelperTest < ActionView::TestCase
assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true) assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false) assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
end end
def test_find_name_by_reflection_should_return_nil_for_missing_record
assert_nil find_name_by_reflection('status', 99)
end
end end