aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/outgoing_message.rb5
-rw-r--r--app/views/request/new_bad_contact.rhtml4
-rw-r--r--config/environment.rb1
-rw-r--r--lib/rack_quote_monkeypatch.rb65
-rw-r--r--spec/controllers/general_controller_spec.rb1
-rw-r--r--spec/controllers/request_controller_spec.rb7
-rw-r--r--spec/integration/search_request_spec.rb9
-rw-r--r--spec/lib/i18n_interpolation.rb15
-rw-r--r--spec/models/outgoing_message_spec.rb7
9 files changed, 109 insertions, 5 deletions
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index c7ba362e0..b7e310b1e 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -54,14 +54,15 @@ class OutgoingMessage < ActiveRecord::Base
# How the default letter starts and ends
def get_salutation
- ret = _("Dear ")
+ ret = ""
if self.message_type == 'followup' && !self.incoming_message_followup.nil? && !self.incoming_message_followup.safe_mail_from.nil? && self.incoming_message_followup.valid_to_reply_to?
ret = ret + OutgoingMailer.name_for_followup(self.info_request, self.incoming_message_followup)
else
ret = ret + self.info_request.public_body.name
end
- return ret + ","
+ salutation = _("Dear {{public_body_name}},", :public_body_name => ret)
end
+
def get_signoff
if self.message_type == 'followup' && !self.incoming_message_followup.nil? && !self.incoming_message_followup.safe_mail_from.nil? && self.incoming_message_followup.valid_to_reply_to?
return _("Yours sincerely,")
diff --git a/app/views/request/new_bad_contact.rhtml b/app/views/request/new_bad_contact.rhtml
index 41a2cef4d..56f3f4168 100644
--- a/app/views/request/new_bad_contact.rhtml
+++ b/app/views/request/new_bad_contact.rhtml
@@ -3,8 +3,8 @@
<h1><%=@title%></h1>
<p><%= _('Unfortunately, we do not have a working {{info_request_law_used_full}}
-address for'),:info_request_law_used_full => @info_request.law_used_full %> <%=h @info_request.public_body.name %>. <%= _('You may be able to find
+address for', :info_request_law_used_full => @info_request.law_used_full) %> <%=h @info_request.public_body.name %>. <%= _('You may be able to find
one on their website, or by phoning them up and asking. If you manage
-to find one, then please <a href="%s">send it to us</a>.') % [help_contact_path] %>
+to find one, then please <a href="{{help_url}}">send it to us</a>.', :help_url => help_contact_path) %>
</p>
diff --git a/config/environment.rb b/config/environment.rb
index 17a16efed..606472740 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -137,3 +137,4 @@ require 'willpaginate_hack.rb'
require 'sendmail_return_path.rb'
require 'tnef.rb'
require 'i18n_fixes.rb'
+require 'rack_quote_monkeypatch.rb'
diff --git a/lib/rack_quote_monkeypatch.rb b/lib/rack_quote_monkeypatch.rb
new file mode 100644
index 000000000..be079c6a2
--- /dev/null
+++ b/lib/rack_quote_monkeypatch.rb
@@ -0,0 +1,65 @@
+# There's a bug in Rack 1.1.x which is fixed in Rack 1.2, but our
+# current version of Rails won't use that. So for now, monkeypatch,
+# This can be dropped when we move to Rails 3.
+#
+# See https://github.com/sebbacon/alaveteli/issues/38 for Alaveteli
+# bug report
+#
+# More info about the monkeypatch:
+# http://thewebfellas.com/blog/2010/7/15/rails-2-3-8-rack-1-1-and-the-curious-case-of-the-missing-quotes
+
+module Rack
+ module Utils
+ def parse_query(qs, d = nil)
+ params = {}
+
+ (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
+ k, v = p.split('=', 2).map { |x| unescape(x) }
+ if cur = params[k]
+ if cur.class == Array
+ params[k] << v
+ else
+ params[k] = [cur, v]
+ end
+ else
+ params[k] = v
+ end
+ end
+
+ return params
+ end
+ module_function :parse_query
+
+ def normalize_params(params, name, v = nil)
+ name =~ %r(\A[\[\]]*([^\[\]]+)\]*)
+ k = $1 || ''
+ after = $' || ''
+
+ return if k.empty?
+
+ if after == ""
+ params[k] = v
+ elsif after == "[]"
+ params[k] ||= []
+ raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
+ params[k] << v
+ elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$)
+ child_key = $1
+ params[k] ||= []
+ raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
+ if params[k].last.is_a?(Hash) && !params[k].last.key?(child_key)
+ normalize_params(params[k].last, child_key, v)
+ else
+ params[k] << normalize_params({}, child_key, v)
+ end
+ else
+ params[k] ||= {}
+ raise TypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Hash)
+ params[k] = normalize_params(params[k], after, v)
+ end
+
+ return params
+ end
+ module_function :normalize_params
+ end
+end
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 76e1bb5e6..3640a8148 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -62,7 +62,6 @@ describe GeneralController, "when searching" do
response.should be_success
end
-
it "should redirect from search query URL to pretty URL" do
post :search_redirect, :query => "mouse" # query hidden in POST parameters
response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index dcd33d279..a9315ddb2 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -308,6 +308,13 @@ describe RequestController, "when creating a new request" do
response.should redirect_to(:controller => 'general', :action => 'frontpage')
end
+ it "should redirect 'bad request' page when a body has no email address" do
+ @body.request_email = ""
+ @body.save!
+ get :new, :public_body_id => @body.id
+ response.should render_template('new_bad_contact')
+ end
+
it "should accept a public body parameter" do
get :new, :public_body_id => @body.id
assigns[:info_request].public_body.should == @body
diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb
new file mode 100644
index 000000000..9398519b7
--- /dev/null
+++ b/spec/integration/search_request_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "When searching" do
+ it "should not strip quotes from quoted query" do
+ request_via_redirect("post", "/search", :query => '"mouse stilton"')
+ response.body.should include("&quot;mouse stilton&quot;")
+ end
+end
+
diff --git a/spec/lib/i18n_interpolation.rb b/spec/lib/i18n_interpolation.rb
new file mode 100644
index 000000000..8c86413ad
--- /dev/null
+++ b/spec/lib/i18n_interpolation.rb
@@ -0,0 +1,15 @@
+# This is a test of the set_content_type monkey patch in
+# lib/tmail_extensions.rb
+
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "when using i18n" do
+
+ it "should not complain if we're missing variables from the string" do
+ result = _('Hello', :dip => 'hummus')
+ result.should == 'Hello'
+ result = _('Hello {{dip}}', :dip => 'hummus')
+ result.should == 'Hello hummus'
+ end
+end
+
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index a9ef57b4f..1956c4d73 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -1,7 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe OutgoingMessage, " when making an outgoing message" do
+ fixtures :outgoing_messages, :info_requests, :incoming_messages, :public_bodies, :public_body_translations
+
before do
+ @om = outgoing_messages(:useless_outgoing_message)
@outgoing_message = OutgoingMessage.new({
:status => 'ready',
:message_type => 'initial_request',
@@ -27,6 +30,10 @@ describe OutgoingMessage, " when making an outgoing message" do
it "should include email addresses in outgoing messages" do
@outgoing_message.body.should include("foo@bar.com")
end
+
+ it "should work out a salutation" do
+ @om.get_salutation.should == "Dear Geraldine Quango,"
+ end
end