diff options
-rw-r--r-- | app/models/request_mailer.rb | 6 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 7 |
2 files changed, 10 insertions, 3 deletions
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index 72c826eac..e4996fcd2 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.44 2008-08-29 09:44:31 francis Exp $ +# $Id: request_mailer.rb,v 1.45 2008-08-29 10:33:45 francis Exp $ class RequestMailer < ApplicationMailer @@ -263,9 +263,9 @@ class RequestMailer < ApplicationMailer def self.alert_comment_on_request() #STDERR.puts "alert_comment_on_request" # We only check comments made in the last month - this means if the - # cron jobs broke fro more than a month events would be lost, but no + # cron jobs broke for more than a month events would be lost, but no # matter. I suspect the performance gain will be needed (with an index on updated_at) - info_requests = InfoRequest.find(:all, :conditions => [ "(select count(*) from info_request_events where event_type = 'comment' and info_request_events.info_request_id = info_requests.id and updated_at > ?) > 0", Time.now() - 1.month ], :include => [ { :info_request_events => :user_info_request_sent_alerts } ], :order => "info_requests.id" ) + info_requests = InfoRequest.find(:all, :conditions => [ "(select count(*) from info_request_events where event_type = 'comment' and info_request_events.info_request_id = info_requests.id and created_at > ?) > 0", Time.now() - 1.month ], :include => [ { :info_request_events => :user_info_request_sent_alerts } ], :order => "info_requests.id" ) for info_request in info_requests #STDERR.puts "considering request " + info_request.id.to_s diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index b63dbbe2f..768369588 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -395,6 +395,13 @@ describe RequestController, "comment alerts" do fixtures :info_requests, :info_request_events, :public_bodies, :users, :incoming_messages, :outgoing_messages, :comments # all needed as integrating views it "should send an alert" do + # updated created_at timestamp, 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.created_at = Time.now() + existing_comment.save! + + # send comment alert RequestMailer.alert_comment_on_request deliveries = ActionMailer::Base.deliveries |