ActionMailer test does not work in Rails 3.2.8

I have a test in notifier_test.rb where Notifier is my mailing class

mail = Notifier.registered_client(client.firstname, client.emailaddress) assert_match I18n.t('notifier.registered_client.email_body'), mail.body.encoded, 'Email contents should be correct' 

This test was used to transfer to Rails 3.2.8, but the test now fails:

 NotifierTest FAIL (0:00:07.963) should create registration email in English Email contents should be correct. Expected /In\ order\ to\ activate\ your\ company's\ registration\ you\ must\ click\ on\ the\ following\ link:/ to match "\nDear First Name, thanks for registering.\n\nIn order to activate your company\'s registration you must click on the following link:\n\nhttp://localhost:3000/en/clients/activate?email=english%40email.com&key=7b6e6ed1-ac03-4d95-a0d5-6f2541092dd0\n". 

The error occurs because the text of my mail contains an apostrophe, which mail.body.encoded now returns as \' due to a patch for:

CVE-2012-3464 The potential XSS vulnerability in Ruby on Rails described in https://groups.google.com/forum/#!msg/rubyonrails-security/kKGNeMrnmiY/r2yM7xy-G48J

What is the smartest way to either encode the string returned by I18n.t and get the text without an apostrophe from my mail object?

+4
source share
1 answer

I finally got to this using

CGI.unescapeHTML (mail.body.encoded)

so the line

assert_match I18n.t ('notifier.registered_client.email_greeting', name: firstname), CGI.unescapeHTML (mail.body.encoded), 'Email greeting must be present'

tested

+1
source

All Articles