From 36426260527d24f502fd322b4b3173f0ac1a2cc5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 14 Feb 2015 08:57:22 +0000 Subject: [PATCH] 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 --- app/helpers/issues_helper.rb | 6 +++--- test/unit/helpers/issues_helper_test.rb | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index a88adceb9..3870a066d 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -460,14 +460,14 @@ module IssuesHelper end @detail_value_name_by_reflection ||= Hash.new do |hash, key| association = Issue.reflect_on_association(key.first.to_sym) + name = nil if association record = association.klass.find_by_id(key.last) if record - record.name.force_encoding('UTF-8') - hash[key] = record.name + name = record.name.force_encoding('UTF-8') end end - hash[key] ||= nil + hash[key] = name end @detail_value_name_by_reflection[[field, id]] end diff --git a/test/unit/helpers/issues_helper_test.rb b/test/unit/helpers/issues_helper_test.rb index 2062464fd..b275e75db 100644 --- a/test/unit/helpers/issues_helper_test.rb +++ b/test/unit/helpers/issues_helper_test.rb @@ -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, false) end + + def test_find_name_by_reflection_should_return_nil_for_missing_record + assert_nil find_name_by_reflection('status', 99) + end end -- 2.39.5