diff options
author | francis <francis> | 2007-11-13 10:22:14 +0000 |
---|---|---|
committer | francis <francis> | 2007-11-13 10:22:14 +0000 |
commit | 2c90695ca2d6b5be61d4b23e8e9ad3a389fcd5f5 (patch) | |
tree | c897db6b98f2e3ad111ce257135b1e05150f1e1d | |
parent | dc965b43e5784d6dde2f06186cb14c4640da65a4 (diff) |
Test incoming request response emails.
-rw-r--r-- | app/models/incoming_message.rb | 13 | ||||
-rw-r--r-- | app/models/info_request.rb | 6 | ||||
-rw-r--r-- | spec/fixtures/incoming-request-plain.email | 18 | ||||
-rw-r--r-- | spec/models/request_mailer_spec.rb | 14 | ||||
-rw-r--r-- | spec/spec_helper.rb | 10 | ||||
-rw-r--r-- | todo.txt | 4 |
6 files changed, 53 insertions, 12 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 56668582a..0d051d379 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -5,7 +5,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.3 2007-10-30 14:13:46 francis Exp $ +# $Id: incoming_message.rb,v 1.4 2007-11-13 10:22:14 francis Exp $ class IncomingMessage < ActiveRecord::Base belongs_to :info_request @@ -13,16 +13,13 @@ class IncomingMessage < ActiveRecord::Base validates_presence_of :raw_data - # We store the raw email in the database, and parse it into - # a structured TMail every time we get it out again. - def after_initialize - @mail = TMail::Mail.parse(self.raw_data) - @mail.base64_decode - end - # Return the structured TMail::Mail object # Documentation at http://i.loveruby.net/en/projects/tmail/doc/ def mail + if @mail.nil? + @mail = TMail::Mail.parse(self.raw_data) + @mail.base64_decode + end @mail end diff --git a/app/models/info_request.rb b/app/models/info_request.rb index bcda9719d..e6b8c2b0a 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.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: info_request.rb,v 1.11 2007-11-07 11:10:56 francis Exp $ +# $Id: info_request.rb,v 1.12 2007-11-13 10:22:14 francis Exp $ require 'digest/sha1' @@ -27,7 +27,7 @@ class InfoRequest < ActiveRecord::Base raise "id required to make incoming_email" if not self.id incoming_email = MySociety::Config.get("INCOMING_EMAIL_PREFIX", "") incoming_email += "request-" + self.id.to_s - incoming_email += "-" + Digest::SHA1.hexdigest(self.id.to_s + MySociety::Config.get("INCOMING_EMAIL_SECRET"))[0,8] + incoming_email += "-" + Digest::SHA1.hexdigest(self.id.to_s + MySociety::Config.get("INCOMING_EMAIL_SECRET", 'dummysecret'))[0,8] incoming_email += "@" + MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost") return incoming_email end @@ -40,7 +40,7 @@ class InfoRequest < ActiveRecord::Base id = $1.to_i hash = $2 - expected_hash = Digest::SHA1.hexdigest(id.to_s + MySociety::Config.get("INCOMING_EMAIL_SECRET"))[0,8] + expected_hash = Digest::SHA1.hexdigest(id.to_s + MySociety::Config.get("INCOMING_EMAIL_SECRET", 'dummysecret'))[0,8] #print "expected: " + expected_hash + "\nhash: " + hash + "\n" if hash != expected_hash return nil diff --git a/spec/fixtures/incoming-request-plain.email b/spec/fixtures/incoming-request-plain.email new file mode 100644 index 000000000..9072b32cc --- /dev/null +++ b/spec/fixtures/incoming-request-plain.email @@ -0,0 +1,18 @@ +From: Bob Smith <bob@localhost> +To: FOI Person <EMAIL_TO> +Bcc: +Subject: Re: Freedom of Information Request - Why aren't you leaving the house? +Reply-To: +In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail> + +No way! That's so totally a rubbish question. No way am I answering that. + +The Geraldine Quango + +On Wed, Oct 24, 2007 at 11:30:06AM +0100, francis@flourish.org wrote: +> Please let me know why Francis isn't getting ready to leave the house +> to go to the UN talk. +> +> Love, +> +> Francis diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index 712ba2484..030395a2d 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -1,8 +1,20 @@ require File.dirname(__FILE__) + '/../spec_helper' -describe RequestMailer, " when blah" do +describe RequestMailer, " when receiving incoming mail" do + fixtures :info_requests + before do + end + + it "should append it to the appropriate request" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) + ir.incoming_messages.size.should == 1 + end + + it "should XXX when the email is not to any information request" end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2d01d442e..b1427f71d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,3 +22,13 @@ Spec::Runner.configure do |config| # for all of your examples, even those that don't use them. end +# XXX No idea what namespace/class/module to put this in +def receive_incoming_mail(email_name, email_to) + email_name = File.join(Spec::Runner.configuration.fixture_path, email_name) + content = File.read(email_name) + content.gsub!('EMAIL_TO', email_to) + RequestMailer.receive(content) +end + + + @@ -5,6 +5,8 @@ Next ==== Send email to requestor telling them new information has come in +Let them send follow-ups +Do something after 20 working days if you get no response Forgotten password link Email has already been taken hasn't got a link to better place @@ -15,6 +17,7 @@ Work out how to get it to tell you code coverage of .rhtml files Make it validate the HTML maybe with http://www.anodyne.ca/wp-content/uploads/2007/09/be_valid_xhtml.rb Check we call integrate_views for all controllers +Test that actually sending request outgoing mail using deliveries Remove "Outgoing messages is invalid" @@ -52,6 +55,7 @@ Check act to see if can use pseudonym for FOI request? Maybe we SHOULD reveal their email to the public body, why not? +Say that we would like response by email (not postal address) in footer Later ===== |