aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test
diff options
context:
space:
mode:
authorGuilherme Mansur <guilherme.mansur@shopify.com>2019-06-21 15:04:28 -0400
committerGuilherme Mansur <guilherme.mansur@shopify.com>2019-07-14 15:04:25 -0400
commit526a5eb10cbe6092389c07c9529eb44c50fb0af6 (patch)
tree40785bf1668863bb8c60a426935b06723b8ade45 /actionview/test
parent727da1d8cdcab3ff50e399053faf7ba84e05ce03 (diff)
downloadrails-526a5eb10cbe6092389c07c9529eb44c50fb0af6.tar.gz
rails-526a5eb10cbe6092389c07c9529eb44c50fb0af6.tar.bz2
rails-526a5eb10cbe6092389c07c9529eb44c50fb0af6.zip
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 <kaspth@gmail.com>
Diffstat (limited to 'actionview/test')
-rw-r--r--actionview/test/template/template_error_test.rb16
1 files changed, 16 insertions, 0 deletions
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 "#<ActionView::Template::Error: original>", 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