Commit 05e243f58eb89a2198278b71a038d4fffea0292c
1 parent
ae266d7f
Exists in
master
and in
1 other branch
Refs #942 fix double filenames in backtraces
Showing
3 changed files
with
38 additions
and
1 deletions
Show diff stats
app/decorators/backtrace_line_decorator.rb
... | ... | @@ -44,7 +44,9 @@ class BacktraceLineDecorator < Draper::Decorator |
44 | 44 | end |
45 | 45 | |
46 | 46 | def decorated_path |
47 | - file_relative.sub(Backtrace::GEMS_PATH, "<strong>\\1</strong>") | |
47 | + path | |
48 | + .sub(Backtrace::IN_APP_PATH, '') | |
49 | + .sub(Backtrace::GEMS_PATH, "<strong>\\1</strong>") | |
48 | 50 | end |
49 | 51 | |
50 | 52 | private | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +describe BacktraceLineDecorator, type: :decorator do | |
2 | + let(:backtrace_line) do | |
3 | + described_class.new( | |
4 | + number: 884, | |
5 | + file: '/path/to/file/ea315ea4.rb', | |
6 | + method: :instance_eval) | |
7 | + end | |
8 | + let(:backtrace_line_in_app) do | |
9 | + described_class.new( | |
10 | + number: 884, | |
11 | + file: '[PROJECT_ROOT]/path/to/file/ea315ea4.rb', | |
12 | + method: :instance_eval) | |
13 | + end | |
14 | + let(:app) { Fabricate(:app, github_repo: 'foo/bar') } | |
15 | + | |
16 | + describe '#to_s' do | |
17 | + it 'returns a nice string representation of the first line' do | |
18 | + expect(backtrace_line.to_s).to eq('/path/to/file/ea315ea4.rb:884') | |
19 | + end | |
20 | + end | |
21 | + | |
22 | + describe '#link_to_source_file' do | |
23 | + it 'adds a link to the source file' do | |
24 | + link = backtrace_line_in_app.link_to_source_file(app) { 'mytext' } | |
25 | + expect(link).to eq( | |
26 | + '<a target="_blank" href="https://github.com/foo/bar/blob/master/pat' \ | |
27 | + 'h/to/file/ea315ea4.rb#L884">mytext</a>') | |
28 | + end | |
29 | + end | |
30 | +end | ... | ... |
spec/spec_helper.rb
... | ... | @@ -50,6 +50,11 @@ RSpec.configure do |config| |
50 | 50 | init_haml_helpers |
51 | 51 | end |
52 | 52 | |
53 | + config.before(:each, type: :decorator) do |_| | |
54 | + Draper::ViewContext.current.class_eval { include Haml::Helpers } | |
55 | + Draper::ViewContext.current.instance_eval { init_haml_helpers } | |
56 | + end | |
57 | + | |
53 | 58 | config.infer_spec_type_from_file_location! |
54 | 59 | end |
55 | 60 | ... | ... |