Commit 64e824e8d93df4ecfcb5fd80a6018de673547742

Authored by Daniel Beardsley
1 parent 34a4b8a1
Exists in master and in 1 other branch production

Error Email: add similar count to subject

It's pretty useful when visually scanning the messages in my inbox to
see the count in the subject instead of having to open the email.

The relative importance of an email roughly scales with similar_count,
so it's a fairly important piece of info.
app/mailers/mailer.rb
... ... @@ -12,8 +12,11 @@ class Mailer < ActionMailer::Base
12 12 @notice = notice
13 13 @app = notice.app
14 14  
  15 + count = @notice.similar_count
  16 + count = count > 1 ? "(#{count}) " : ""
  17 +
15 18 mail :to => @app.notification_recipients,
16   - :subject => "[#{@app.name}][#{@notice.environment_name}] #{@notice.message.truncate(50)}"
  19 + :subject => "#{count}[#{@app.name}][#{@notice.environment_name}] #{@notice.message.truncate(50)}"
17 20 end
18 21  
19 22 def deploy_notification(deploy)
... ...
spec/mailers/mailer_spec.rb
... ... @@ -10,6 +10,7 @@ describe Mailer do
10 10 before do
11 11 notice.backtrace.lines.last.update_attributes(:file => "[PROJECT_ROOT]/path/to/file.js")
12 12 notice.app.update_attributes :asset_host => "http://example.com"
  13 + notice.problem.update_attributes :notices_count => 3
13 14  
14 15 @email = Mailer.err_notification(notice).deliver
15 16 end
... ... @@ -30,6 +31,10 @@ describe Mailer do
30 31 @email.should have_body_text('<a href="http://example.com/path/to/file.js" target="_blank">path/to/file.js')
31 32 end
32 33  
  34 + it "should have the error count in the subject" do
  35 + @email.subject.should =~ /^\(3\) /
  36 + end
  37 +
33 38 context 'with a very long message' do
34 39 let(:notice) { Fabricate(:notice, :message => 6.times.collect{|a| "0123456789" }.join('')) }
35 40 it "should truncate the long message" do
... ...