aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/request_mailer.rb9
-rw-r--r--spec/controllers/request_controller_spec.rb26
2 files changed, 26 insertions, 9 deletions
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 35b34b0ad..2e0b52de1 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: request_mailer.rb,v 1.80 2009-06-27 03:59:48 francis Exp $
+# $Id: request_mailer.rb,v 1.81 2009-08-18 21:32:23 francis Exp $
class RequestMailer < ApplicationMailer
@@ -375,10 +375,11 @@ class RequestMailer < ApplicationMailer
earliest_unalerted_comment_event = nil
count = 0
for e in info_request.info_request_events.reverse
- # STDERR.puts "event " + e.id.to_s + " type " + e.event_type
- if e.event_type == 'comment'
+ #STDERR.puts "event " + e.id.to_s + " type " + e.event_type
+ # alert on comments, which were not made by the user who originally made the request
+ if e.event_type == 'comment' && e.comment.user_id != info_request.user_id
alerted_for = e.user_info_request_sent_alerts.find(:first, :conditions => [ "alert_type = 'comment_1' and user_id = ?", info_request.user_id])
- # STDERR.puts "is comment, alerted_for " + alerted_for.to_s
+ #STDERR.puts "is comment by other user, alerted_for " + alerted_for.to_s + " comment user " + e.comment.user_id.to_s + " request user " + info_request.user_id.to_s + " body: " + e.comment.body
if alerted_for.nil?
# STDERR.puts "nil!"
count = count + 1
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index e8bf5c1fc..f40c2770f 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -797,7 +797,7 @@ describe RequestController, "comment alerts" do
existing_comment = info_requests(:fancy_dog_request).comments[0]
existing_comment.info_request_events[0].destroy
existing_comment.destroy
- new_comment = info_requests(:fancy_dog_request).add_comment('I love making annotations.', users(:bob_smith_user))
+ new_comment = info_requests(:fancy_dog_request).add_comment('I really love making annotations.', users(:silly_name_user))
# send comment alert
RequestMailer.alert_comment_on_request
@@ -816,11 +816,27 @@ describe RequestController, "comment alerts" do
#STDERR.puts mail.body
end
+ it "should not send an alert when you comment on your own request" do
+ # delete ficture comment and make new one, so is in last month (as
+ # alerts are only for comments in last month, see
+ # RequestMailer.alert_comment_on_request)
+ existing_comment = info_requests(:fancy_dog_request).comments[0]
+ existing_comment.info_request_events[0].destroy
+ existing_comment.destroy
+ new_comment = info_requests(:fancy_dog_request).add_comment('I also love making annotations.', users(:bob_smith_user))
+
+ # try to send comment alert
+ RequestMailer.alert_comment_on_request
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
+ end
+
it "should send an alert when there are two new comments" do
- # add second comment - that one being new will be enough for
- # RequestMailer.alert_comment_on_request to also find the one in the
- # fixture.
- new_comment = info_requests(:fancy_dog_request).add_comment('Not as daft as this one', users(:bob_smith_user))
+ # add two comments - the second one sould be ignored, as is by the user who made the request.
+ # the new comment here, will cause the one in the fixture to be picked up as a new comment by alert_comment_on_request also.
+ new_comment = info_requests(:fancy_dog_request).add_comment('Not as daft as this one', users(:silly_name_user))
+ new_comment = info_requests(:fancy_dog_request).add_comment('Or this one!!!', users(:bob_smith_user))
RequestMailer.alert_comment_on_request