From 526a5eb10cbe6092389c07c9529eb44c50fb0af6 Mon Sep 17 00:00:00 2001 From: Guilherme Mansur Date: Fri, 21 Jun 2019 15:04:28 -0400 Subject: Empty array instead of nil for source_extract The source_extract method will return nil when it can't find the file name in the backtrace, methods that consume this method expect an array and the nil ends up causing type errors down the road like it happened here: #36341. This patch refactors the source_extract method so that it returns an empty array instead of nil when it can't find the source code. Co-authored-by: Kasper Timm Hansen --- actionview/test/template/template_error_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'actionview/test') diff --git a/actionview/test/template/template_error_test.rb b/actionview/test/template/template_error_test.rb index c4dc88e4aa..643c29602b 100644 --- a/actionview/test/template/template_error_test.rb +++ b/actionview/test/template/template_error_test.rb @@ -34,4 +34,20 @@ class TemplateErrorTest < ActiveSupport::TestCase assert_equal "#", error.inspect end + + def test_annotated_source_code_returns_empty_array_if_source_cant_be_found + template = Class.new do + def identifier + "something" + end + end.new + + error = begin + raise + rescue + raise ActionView::Template::Error.new(template) rescue $! + end + + assert_equal [], error.annotated_source_code + end end -- cgit v1.2.3