Skip to content

Commit

Permalink
Fix nil reference in BacktraceLineDecorator (#1260)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevecrozz committed Feb 13, 2018
1 parent 3873555 commit 9b85558
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/decorators/backtrace_line_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,7 +15,7 @@ def column
end

def file
object[:file]
object[:file].to_s
end

def method
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions spec/decorators/backtrace_line_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' }
Expand Down

0 comments on commit 9b85558

Please sign in to comment.