From f2f02b6ca346f67f96d076b0cbbad93c11c9d6bc Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 5 Mar 2013 22:57:02 +1300 Subject: [PATCH] Add links to source files in notification emails --- app/mailers/mailer.rb | 1 + app/models/backtrace_line.rb | 2 +- app/views/mailer/err_notification.html.haml | 9 ++++++--- app/views/notices/_backtrace_line.html.haml | 2 +- spec/mailers/mailer_spec.rb | 18 ++++++++++++++---- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 2429f8e..040c416 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -4,6 +4,7 @@ require Rails.root.join('config/routes.rb') class Mailer < ActionMailer::Base helper ApplicationHelper + helper BacktraceLineHelper default :from => Errbit::Config.email_from diff --git a/app/models/backtrace_line.rb b/app/models/backtrace_line.rb index b68cbe7..f517ad8 100644 --- a/app/models/backtrace_line.rb +++ b/app/models/backtrace_line.rb @@ -15,7 +15,7 @@ class BacktraceLine delegate :app, :to => :backtrace def to_s - "#{file}:#{number}" << (column.present? ? ":#{column}" : "") + "#{file_relative}:#{number}" << (column.present? ? ":#{column}" : "") end def in_app? diff --git a/app/views/mailer/err_notification.html.haml b/app/views/mailer/err_notification.html.haml index c376629..1cc4068 100644 --- a/app/views/mailer/err_notification.html.haml +++ b/app/views/mailer/err_notification.html.haml @@ -28,7 +28,9 @@ %p.monospace = @notice.where - @notice.in_app_backtrace_lines.each do |line| - %p.backtrace= line + %p.backtrace + = link_to_source_file(line) do + = line.to_s %br %p.heading URL: %p.monospace @@ -40,6 +42,7 @@ %br %p.heading FULL BACKTRACE: - @notice.backtrace_lines.each do |line| - %p.backtrace= line + %p.backtrace + = link_to_source_file(line) do + = line.to_s %br - diff --git a/app/views/notices/_backtrace_line.html.haml b/app/views/notices/_backtrace_line.html.haml index 2517610..62402aa 100644 --- a/app/views/notices/_backtrace_line.html.haml +++ b/app/views/notices/_backtrace_line.html.haml @@ -1,7 +1,7 @@ %tr{:class => defined?(row_class) && row_class} %td.line{:class => line.in_app? && 'in-app' } = link_to_source_file(line) do - %span.path>=raw line.decorated_path + %span.path>= raw line.decorated_path %span.file>= line.file_name - if line.number.present? %span.number>= ":#{line.number}" diff --git a/spec/mailers/mailer_spec.rb b/spec/mailers/mailer_spec.rb index fc0f87c..2f19dc8 100644 --- a/spec/mailers/mailer_spec.rb +++ b/spec/mailers/mailer_spec.rb @@ -6,24 +6,34 @@ describe Mailer do include EmailSpec::Matchers let(:notice) { Fabricate(:notice, :message => "class < ActionController::Base") } - let!(:email) { Mailer.err_notification(notice).deliver } + + before do + notice.backtrace.lines.last.update_attributes(:file => "[PROJECT_ROOT]/path/to/file.js") + notice.app.update_attributes :asset_host => "http://example.com" + + @email = Mailer.err_notification(notice).deliver + end it "should send the email" do ActionMailer::Base.deliveries.size.should == 1 end it "should html-escape the notice's message for the html part" do - email.should have_body_text("class < ActionController::Base") + @email.should have_body_text("class < ActionController::Base") end it "should have inline css" do - email.should have_body_text('

path/to/file.js') end context 'with a very long message' do let(:notice) { Fabricate(:notice, :message => 6.times.collect{|a| "0123456789" }.join('')) } it "should truncate the long message" do - email.subject.should =~ / \d{47}\.{3}$/ + @email.subject.should =~ / \d{47}\.{3}$/ end end end -- libgit2 0.21.2