aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2007-12-12 23:35:09 +0000
committerfrancis <francis>2007-12-12 23:35:09 +0000
commit07751d94086bc9330bbe0728c8d022362c9c8571 (patch)
tree56420f703762a83ab3aaecc95cd22d8f569c9bbc
parent6ada66a26ba65866f9c88dc040fb5271ac5110ee (diff)
Word wrap emails.
Fix user id references in test code.
-rw-r--r--app/models/request_mailer.rb3
-rw-r--r--app/views/layouts/request_mailer.rhtml1
-rw-r--r--app/views/request_mailer/bounced_message.rhtml3
-rw-r--r--app/views/request_mailer/initial_request.rhtml2
-rw-r--r--config/environment.rb1
-rwxr-xr-xscript/wraptest41
-rw-r--r--spec/controllers/request_controller_spec.rb4
-rw-r--r--spec/controllers/user_controller_spec.rb10
-rw-r--r--spec/models/request_mailer_spec.rb3
9 files changed, 55 insertions, 13 deletions
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 5b9e2d1ed..70f396d61 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.8 2007-12-11 12:09:37 francis Exp $
+# $Id: request_mailer.rb,v 1.9 2007-12-12 23:35:09 francis Exp $
class RequestMailer < ActionMailer::Base
@@ -27,6 +27,7 @@ class RequestMailer < ActionMailer::Base
end
def new_response(info_request, incoming_message)
+ raise "foo" + (info_request.user.nil? ? 't' : 'f')
post_redirect = PostRedirect.new(
:uri => classify_request_url(:incoming_message_id => incoming_message.id),
:user_id => info_request.user.id)
diff --git a/app/views/layouts/request_mailer.rhtml b/app/views/layouts/request_mailer.rhtml
new file mode 100644
index 000000000..ce5c18c5b
--- /dev/null
+++ b/app/views/layouts/request_mailer.rhtml
@@ -0,0 +1 @@
+<%= MySociety::Format.wrap_email_body(yield) %>
diff --git a/app/views/request_mailer/bounced_message.rhtml b/app/views/request_mailer/bounced_message.rhtml
index 8c42bd1b5..cdb8e8ddf 100644
--- a/app/views/request_mailer/bounced_message.rhtml
+++ b/app/views/request_mailer/bounced_message.rhtml
@@ -1,4 +1,3 @@
-An incoming email arrived which was not to a known FOI request. Find the
-message attached.
+An incoming email arrived which was not to a known FOI request. Find the message attached.
This message was sent by mysociety/foi/models/request_mailer.rb.
diff --git a/app/views/request_mailer/initial_request.rhtml b/app/views/request_mailer/initial_request.rhtml
index e72439208..67271a122 100644
--- a/app/views/request_mailer/initial_request.rhtml
+++ b/app/views/request_mailer/initial_request.rhtml
@@ -1,5 +1,3 @@
-Dear <%= @info_request.public_body.name %>,
-
<%= @outgoing_message.body %>
--
diff --git a/config/environment.rb b/config/environment.rb
index 42f44efed..ccf4c9ed6 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -16,6 +16,7 @@ $:.push(File.join(File.dirname(__FILE__), '../../rblib'))
load "validate.rb"
load "config.rb"
+load "format.rb"
Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here
diff --git a/script/wraptest b/script/wraptest
new file mode 100755
index 000000000..d15d255b3
--- /dev/null
+++ b/script/wraptest
@@ -0,0 +1,41 @@
+#!/usr/bin/ruby
+#
+# wraptest:
+# Test email wrapping function
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
+#
+
+$:.push(File.join(File.dirname(__FILE__), '../../rblib'))
+load "format.rb"
+
+test_email = '''Dear Sir or Madam,
+
+Again and again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet again I extend this sentence and yet
+
+Hey you.
+
+Yours faithfully,
+
+Boo!
+
+--
+
+Sent using GovernmentSpy, a project of UKCOD, registered charity number
+1076346. Is frabcus@fastmail.fm the wrong
+address for Freedom of Information requests to The Geraldine Quango? If so please let us know by emailing
+team@governmentspy quoting reference PB2.
+We\'ll make sure future ones go to the right place.
+'''
+
+puts MySociety::Format.wrap_email_body(test_email)
+
+#puts MySociety::Format.wrap_email_body("Hello this is a string.
+#
+#And another.
+#And a third.")
+
+
+
+
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 26555aaa0..40a50adac 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -15,7 +15,7 @@ describe RequestController, "when showing the front page" do
end
it "should have sign out link when signed in" do
- session[:user] = users(:bob_smith_user)
+ session[:user_id] = users(:bob_smith_user).id
get :frontpage
response.should have_tag('a', "Sign out")
end
@@ -122,7 +122,7 @@ describe RequestController, "when creating a new request" do
end
it "should create the request and outgoing message and redirect to request page when input is good and somebody is logged in" do
- session[:user] = users(:bob_smith_user)
+ session[:user_id] = users(:bob_smith_user).id
post :create, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id,
:title => "Why is your quango called Geraldine?"},
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index cf73e5d13..76d93a193 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -77,7 +77,7 @@ describe UserController, "when signing in" do
post :signin, { :user => { :email => 'bob@localhost', :password => 'jonespassword' },
:token => post_redirect.token
}
- session[:user].should == users(:bob_smith_user).id
+ session[:user_id].should == users(:bob_smith_user).id
response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1)
response.should_not send_email
end
@@ -147,16 +147,16 @@ describe UserController, "when signing out" do
fixtures :users
it "should log you out and redirect to the home page" do
- session[:user] = users(:bob_smith_user).id
+ session[:user_id] = users(:bob_smith_user).id
get :signout
- session[:user].should be_nil
+ session[:user_id].should be_nil
response.should redirect_to(:controller => 'request', :action => 'frontpage')
end
it "should log you out and redirect you to where you were" do
- session[:user] = users(:bob_smith_user).id
+ session[:user_id] = users(:bob_smith_user).id
get :signout, :r => '/list'
- session[:user].should be_nil
+ session[:user_id].should be_nil
response.should redirect_to(:controller => 'request', :action => 'list')
end
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 67a9536af..43f5a3c38 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -9,8 +9,9 @@ describe RequestMailer, " when receiving incoming mail" do
it "should append it to the appropriate request" do
ir = info_requests(:fancy_dog_request)
+ ir.incoming_messages.size.should == 1 # in the fixture
receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
- ir.incoming_messages.size.should == 2
+ ir.incoming_messages.size.should == 2 # one more arrives
end
it "should bounce email to admin when the email is not to any information request" do