Commit dc6be7cfe4acb2ba5483d0e868004b9527ed5a5e
Committed by
Daniela Feitosa
1 parent
9731f6e8
Exists in
master
and in
29 other branches
Test if has emails to be notified before delivering mails
(ActionItem1811)
Showing
2 changed files
with
11 additions
and
5 deletions
Show diff stats
app/models/comment.rb
... | ... | @@ -68,7 +68,7 @@ class Comment < ActiveRecord::Base |
68 | 68 | end |
69 | 69 | |
70 | 70 | after_create do |comment| |
71 | - if comment.article.notify_comments? | |
71 | + if comment.article.notify_comments? && !comment.article.profile.notification_emails.empty? | |
72 | 72 | Comment::Notifier.deliver_mail(comment) |
73 | 73 | end |
74 | 74 | end |
... | ... | @@ -76,10 +76,7 @@ class Comment < ActiveRecord::Base |
76 | 76 | class Notifier < ActionMailer::Base |
77 | 77 | def mail(comment) |
78 | 78 | profile = comment.article.profile |
79 | - email = profile.notification_emails | |
80 | - return unless email | |
81 | - recipients email | |
82 | - | |
79 | + recipients profile.notification_emails | |
83 | 80 | from "#{profile.environment.name} <#{profile.environment.contact_email}>" |
84 | 81 | subject _("[%s] you got a new comment!") % [profile.environment.name] |
85 | 82 | body :recipient => profile.nickname || profile.name, | ... | ... |
test/unit/comment_notifier_test.rb
... | ... | @@ -56,6 +56,15 @@ class CommentNotifierTest < Test::Unit::TestCase |
56 | 56 | assert_match /comment body/, sent.body |
57 | 57 | end |
58 | 58 | |
59 | + should 'not deliver mail if has no notification emails' do | |
60 | + community = fast_create(Community) | |
61 | + assert_equal [], community.notification_emails | |
62 | + article = fast_create(Article, :name => 'Article test', :profile_id => community.id, :notify_comments => true) | |
63 | + assert_no_difference ActionMailer::Base.deliveries, :size do | |
64 | + article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'there is no addresses to send notification') | |
65 | + end | |
66 | + end | |
67 | + | |
59 | 68 | private |
60 | 69 | |
61 | 70 | def read_fixture(action) | ... | ... |