From d8a4e4b49481976390a9a8342eca7888eaddc404 Mon Sep 17 00:00:00 2001 From: Alvaro Bautista Date: Tue, 9 Apr 2013 09:27:36 +0000 Subject: [PATCH] Use comment notification recipients in mailer --- app/mailers/mailer.rb | 3 +-- spec/mailers/mailer_spec.rb | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 2bde6bc..a33256f 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -34,8 +34,7 @@ class Mailer < ActionMailer::Base @notice = @problem.notices.first @app = @problem.app - # Don't send comment notification to user who posted the comment - recipients = @app.notification_recipients - [comment.user.email] + recipients = @comment.notification_recipients mail :to => recipients, :subject => "#{@user.name} commented on [#{@app.name}][#{@notice.environment_name}] #{@notice.message.truncate(50)}" diff --git a/spec/mailers/mailer_spec.rb b/spec/mailers/mailer_spec.rb index 69dec00..f645128 100644 --- a/spec/mailers/mailer_spec.rb +++ b/spec/mailers/mailer_spec.rb @@ -46,5 +46,36 @@ describe Mailer do end end end -end + context "Comment Notification" do + include EmailSpec::Helpers + include EmailSpec::Matchers + + let!(:notice) { Fabricate(:notice) } + let!(:comment) { Fabricate.build(:comment, :err => notice.problem) } + let!(:watcher) { Fabricate(:watcher, :app => comment.app) } + let(:recipients) { ['recipient@example.com', 'another@example.com']} + + before do + comment.stub(:notification_recipients).and_return(recipients) + Fabricate(:notice, :err => notice.err) + @email = Mailer.comment_notification(comment).deliver + end + + it "should send the email" do + ActionMailer::Base.deliveries.size.should == 1 + end + + it "should be sent to comment notification recipients" do + @email.to.should == recipients + end + + it "should have the notices count in the body" do + @email.should have_body_text("This err has occurred 2 times") + end + + it "should have the comment body" do + @email.should have_body_text(comment.body) + end + end +end -- libgit2 0.21.2