diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-02-15 16:08:15 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-02-15 16:08:15 +0000 |
commit | 368d2482f23b019a3a1582fc6b49e94c6f91d4bb (patch) | |
tree | 72ee72d03dc084e79bb6f7deb3b554af845854ac | |
parent | bc0cc811e80143d0255d86433a80a823d1141dd0 (diff) | |
parent | feefa1b5d9c8765cef63dd6601805b912e7d475c (diff) |
Merge branch 'hotfix/0.7.0.1'0.7.0.1
-rw-r--r-- | app/models/application_mailer.rb | 14 | ||||
-rw-r--r-- | spec/models/request_mailer_spec.rb | 21 |
2 files changed, 35 insertions, 0 deletions
diff --git a/app/models/application_mailer.rb b/app/models/application_mailer.rb index cdb279c3c..1a97a4bf9 100644 --- a/app/models/application_mailer.rb +++ b/app/models/application_mailer.rb @@ -77,6 +77,17 @@ class ApplicationMailer < ActionMailer::Base # and via template_path, which is created from it) in the create! method when # looking for templates. Our modified version looks for templates in the view_paths # in order. + + # It also has a line converting the mail subject to a string. This is because we + # use translated strings in the subject lines, sometimes in conjunction with + # user input, like request titles. The _() function used for translation + # returns an instance of SafeBuffer, which doesn't handle gsub calls in the block form + # with $ variables - https://github.com/rails/rails/issues/1555. + # Unfortunately ActionMailer uses that form in quoted_printable(), which will be + # called if any part of the subject requires quoting. So we convert the subject + # back to a string via to_str() before passing in to create_mail. There is a test + # for this in spec/models/request_mailer_spec.rb + # Changed lines marked with *** # Initialize the mailer via the given +method_name+. The body will be @@ -139,6 +150,9 @@ class ApplicationMailer < ActionMailer::Base # already set. @mime_version ||= "1.0" if !@parts.empty? + # *** Convert into a string + @subject = @subject.to_str if @subject + # build the mail object itself @mail = create_mail end diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index 5edc8edb6..20d401a63 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -327,6 +327,27 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla end + +describe RequestMailer, 'when sending a new response email' do + + before do + @user = mock_model(User, :name_and_email => 'test name and email') + @public_body = mock_model(PublicBody, :name => 'Test public body') + @info_request = mock_model(InfoRequest, :user => @user, + :law_used_full => 'Freedom of Information', + :title => 'Here is a character that needs quoting …', + :public_body => @public_body, + :display_status => 'Refused.', + :url_title => 'test_request') + @incoming_message = mock_model(IncomingMessage, :info_request => @info_request) + end + + it 'should not error when sending mails requests with characters requiring quoting in the subject' do + @mail = RequestMailer.create_new_response(@info_request, @incoming_message) + end + +end + describe RequestMailer, 'requires_admin' do before(:each) do user = mock_model(User, :name_and_email => 'Bruce Jones', |