diff --git a/app/decorators/backtrace_line_decorator.rb b/app/decorators/backtrace_line_decorator.rb index 16cd69a39..262ac3ecc 100644 --- a/app/decorators/backtrace_line_decorator.rb +++ b/app/decorators/backtrace_line_decorator.rb @@ -2,7 +2,8 @@ class BacktraceLineDecorator < Draper::Decorator EMPTY_STRING = ''.freeze def in_app? - object[:file].match Backtrace::IN_APP_PATH + return false if file.blank? + file.match Backtrace::IN_APP_PATH end def number @@ -14,7 +15,7 @@ def column end def file - object[:file] + object[:file].to_s end def method @@ -40,7 +41,8 @@ def link_to_source_file(app, &block) end def path - File.dirname(object[:file]).gsub(/^\.$/, '') + "/" + return '' if file.blank? + File.dirname(file).gsub(/^\.$/, '') + "/" end def decorated_path diff --git a/spec/decorators/backtrace_line_decorator_spec.rb b/spec/decorators/backtrace_line_decorator_spec.rb index 873118f17..03e78f08e 100644 --- a/spec/decorators/backtrace_line_decorator_spec.rb +++ b/spec/decorators/backtrace_line_decorator_spec.rb @@ -11,6 +11,9 @@ file: '[PROJECT_ROOT]/path/to/file/ea315ea4.rb', method: :instance_eval) end + let(:backtrace_line_no_file) do + described_class.new(number: 884, method: :instance_eval) + end let(:app) { Fabricate(:app, github_repo: 'foo/bar') } describe '#to_s' do @@ -19,6 +22,24 @@ end end + describe '#file' do + it 'returns "" when there is no file' do + expect(backtrace_line_no_file.file).to eq('') + end + end + + describe '#in_app?' do + it 'returns false when there is no file' do + expect(backtrace_line_no_file.in_app?).to be false + end + end + + describe '#path' do + it 'returns "" when there is no file' do + expect(backtrace_line_no_file.path).to eq '' + end + end + describe '#link_to_source_file' do it 'adds a link to the source file' do link = backtrace_line_in_app.link_to_source_file(app) { 'mytext' }