The tests assumed that every part in the multipart emails that we send were either plain text or HTML. Now we have image attachments, against whose contents the tests were still trying to match regexes. The tests have been modified to only run regexes on the text parts of the mails.
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
- register_email.parts.each do |part|
+ email_text_parts(register_email).each do |part|
assert_match confirm_regex, part.body.to_s
end
assert_match confirm_regex, part.body.to_s
end
- confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
+ confirm_string = email_text_parts(register_email)[0].body.match(confirm_regex)[1]
# Check the page
assert_response :success
# Check the page
assert_response :success
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
- register_email.parts.each do |part|
+ email_text_parts(register_email).each do |part|
assert_match confirm_regex, part.body.to_s
end
assert_match confirm_regex, part.body.to_s
end
- confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
+ confirm_string = email_text_parts(register_email)[0].body.match(confirm_regex)[1]
# Check the page
assert_response :success
# Check the page
assert_response :success
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
- register_email.parts.each do |part|
+ email_text_parts(register_email).each do |part|
assert_match confirm_regex, part.body.to_s
end
assert_match confirm_regex, part.body.to_s
end
- confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
+ confirm_string = email_text_parts(register_email)[0].body.match(confirm_regex)[1]
# Check the page
assert_response :success
# Check the page
assert_response :success
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
- register_email.parts.each do |part|
+ email_text_parts(register_email).each do |part|
assert_match confirm_regex, part.body.to_s
end
assert_match confirm_regex, part.body.to_s
end
- confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
+ confirm_string = email_text_parts(register_email)[0].body.match(confirm_regex)[1]
# Check the page
assert_response :success
# Check the page
assert_response :success
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
- register_email.parts.each do |part|
+ email_text_parts(register_email).each do |part|
assert_match confirm_regex, part.body.to_s
end
assert_match confirm_regex, part.body.to_s
end
- confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
+ confirm_string = email_text_parts(register_email)[0].body.match(confirm_regex)[1]
# Check the page
assert_response :success
# Check the page
assert_response :success
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
- register_email.parts.each do |part|
+ email_text_parts(register_email).each do |part|
assert_match confirm_regex, part.body.to_s
end
assert_match confirm_regex, part.body.to_s
end
- confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
+ confirm_string = email_text_parts(register_email)[0].body.match(confirm_regex)[1]
# Check the page
assert_response :success
# Check the page
assert_response :success
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
assert_equal register_email.to[0], new_email
# Check that the confirm account url is correct
confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
- register_email.parts.each do |part|
+ email_text_parts(register_email).each do |part|
assert_match confirm_regex, part.body.to_s
end
assert_match confirm_regex, part.body.to_s
end
- confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
+ confirm_string = email_text_parts(register_email)[0].body.match(confirm_regex)[1]
# Check the page
assert_response :success
# Check the page
assert_response :success
stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0")
stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1")
end
stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0")
stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1")
end
+
+ def email_text_parts(message)
+ text_parts = []
+ message.parts.each do |part|
+ if part.content_type.start_with?("text/")
+ text_parts.push(part)
+ elsif part.multipart?
+ text_parts.concat(email_text_parts(part))
+ end
+ end
+ return text_parts
+ end