Commit f2f02b6ca346f67f96d076b0cbbad93c11c9d6bc

Authored by Nathan Broadbent
1 parent 07cd269d
Exists in master and in 1 other branch production

Add links to source files in notification emails

app/mailers/mailer.rb
... ... @@ -4,6 +4,7 @@ require Rails.root.join('config/routes.rb')
4 4  
5 5 class Mailer < ActionMailer::Base
6 6 helper ApplicationHelper
  7 + helper BacktraceLineHelper
7 8  
8 9 default :from => Errbit::Config.email_from
9 10  
... ...
app/models/backtrace_line.rb
... ... @@ -15,7 +15,7 @@ class BacktraceLine
15 15 delegate :app, :to => :backtrace
16 16  
17 17 def to_s
18   - "#{file}:#{number}" << (column.present? ? ":#{column}" : "")
  18 + "#{file_relative}:#{number}" << (column.present? ? ":#{column}" : "")
19 19 end
20 20  
21 21 def in_app?
... ...
app/views/mailer/err_notification.html.haml
... ... @@ -28,7 +28,9 @@
28 28 %p.monospace
29 29 = @notice.where
30 30 - @notice.in_app_backtrace_lines.each do |line|
31   - %p.backtrace= line
  31 + %p.backtrace
  32 + = link_to_source_file(line) do
  33 + = line.to_s
32 34 %br
33 35 %p.heading URL:
34 36 %p.monospace
... ... @@ -40,6 +42,7 @@
40 42 %br
41 43 %p.heading FULL BACKTRACE:
42 44 - @notice.backtrace_lines.each do |line|
43   - %p.backtrace= line
  45 + %p.backtrace
  46 + = link_to_source_file(line) do
  47 + = line.to_s
44 48 %br
45   -
... ...
app/views/notices/_backtrace_line.html.haml
1 1 %tr{:class => defined?(row_class) && row_class}
2 2 %td.line{:class => line.in_app? && 'in-app' }
3 3 = link_to_source_file(line) do
4   - %span.path>=raw line.decorated_path
  4 + %span.path>= raw line.decorated_path
5 5 %span.file>= line.file_name
6 6 - if line.number.present?
7 7 %span.number>= ":#{line.number}"
... ...
spec/mailers/mailer_spec.rb
... ... @@ -6,24 +6,34 @@ describe Mailer do
6 6 include EmailSpec::Matchers
7 7  
8 8 let(:notice) { Fabricate(:notice, :message => "class < ActionController::Base") }
9   - let!(:email) { Mailer.err_notification(notice).deliver }
  9 +
  10 + before do
  11 + notice.backtrace.lines.last.update_attributes(:file => "[PROJECT_ROOT]/path/to/file.js")
  12 + notice.app.update_attributes :asset_host => "http://example.com"
  13 +
  14 + @email = Mailer.err_notification(notice).deliver
  15 + end
10 16  
11 17 it "should send the email" do
12 18 ActionMailer::Base.deliveries.size.should == 1
13 19 end
14 20  
15 21 it "should html-escape the notice's message for the html part" do
16   - email.should have_body_text("class &lt; ActionController::Base")
  22 + @email.should have_body_text("class &lt; ActionController::Base")
17 23 end
18 24  
19 25 it "should have inline css" do
20   - email.should have_body_text('<p class="backtrace" style="')
  26 + @email.should have_body_text('<p class="backtrace" style="')
  27 + end
  28 +
  29 + it "should have links to source files" do
  30 + @email.should have_body_text('<a href="http://example.com/path/to/file.js" target="_blank">path/to/file.js')
21 31 end
22 32  
23 33 context 'with a very long message' do
24 34 let(:notice) { Fabricate(:notice, :message => 6.times.collect{|a| "0123456789" }.join('')) }
25 35 it "should truncate the long message" do
26   - email.subject.should =~ / \d{47}\.{3}$/
  36 + @email.subject.should =~ / \d{47}\.{3}$/
27 37 end
28 38 end
29 39 end
... ...