From dc6be7cfe4acb2ba5483d0e868004b9527ed5a5e Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Mon, 17 Jan 2011 16:33:21 -0300 Subject: [PATCH] Test if has emails to be notified before delivering mails --- app/models/comment.rb | 7 ++----- test/unit/comment_notifier_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 0bd61d7..613d010 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -68,7 +68,7 @@ class Comment < ActiveRecord::Base end after_create do |comment| - if comment.article.notify_comments? + if comment.article.notify_comments? && !comment.article.profile.notification_emails.empty? Comment::Notifier.deliver_mail(comment) end end @@ -76,10 +76,7 @@ class Comment < ActiveRecord::Base class Notifier < ActionMailer::Base def mail(comment) profile = comment.article.profile - email = profile.notification_emails - return unless email - recipients email - + recipients profile.notification_emails from "#{profile.environment.name} <#{profile.environment.contact_email}>" subject _("[%s] you got a new comment!") % [profile.environment.name] body :recipient => profile.nickname || profile.name, diff --git a/test/unit/comment_notifier_test.rb b/test/unit/comment_notifier_test.rb index b4a7a38..3b9c38e 100644 --- a/test/unit/comment_notifier_test.rb +++ b/test/unit/comment_notifier_test.rb @@ -56,6 +56,15 @@ class CommentNotifierTest < Test::Unit::TestCase assert_match /comment body/, sent.body end + should 'not deliver mail if has no notification emails' do + community = fast_create(Community) + assert_equal [], community.notification_emails + article = fast_create(Article, :name => 'Article test', :profile_id => community.id, :notify_comments => true) + assert_no_difference ActionMailer::Base.deliveries, :size do + article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'there is no addresses to send notification') + end + end + private def read_fixture(action) -- libgit2 0.21.2