Skip to content
Browse files

Merge pull request #5045 from avakhov/am-format-paragraph-fix

Fix AM format_paragraph helper method if a first word is long
  • Loading branch information...
2 parents 1c75b9a + 7f33a44 commit 2f9e47713051e211a1866bb8e7af3151e70a9ba0 @josevalim josevalim committed Feb 15, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −1 actionmailer/lib/action_mailer/mail_helper.rb
  2. +13 −0 actionmailer/test/mail_helper_test.rb
View
2 actionmailer/lib/action_mailer/mail_helper.rb
@@ -41,7 +41,7 @@ def format_paragraph(text, len = 72, indent = 2)
sentences = [[]]
text.split.each do |word|
- if (sentences.last + [word]).join(' ').length > len
+ if sentences.first.present? && (sentences.last + [word]).join(' ').length > len
sentences << [word]
else
sentences.last << word
View
13 actionmailer/test/mail_helper_test.rb
@@ -22,6 +22,14 @@ def use_format_paragraph
end
end
+ def use_format_paragraph_with_long_first_word
+ @text = "Antidisestablishmentarianism is very long."
+
+ mail_with_defaults do |format|
+ format.html { render(:inline => "<%= format_paragraph @text, 10, 1 %>") }
+ end
+ end
+
def use_mailer
mail_with_defaults do |format|
format.html { render(:inline => "<%= mailer.message.subject %>") }
@@ -81,6 +89,11 @@ def test_use_format_paragraph
assert_match " But soft! What\r\n light through\r\n yonder window\r\n breaks?", mail.body.encoded
end
+ def test_use_format_paragraph_with_long_first_word
+ mail = HelperMailer.use_format_paragraph_with_long_first_word
+ assert_equal " Antidisestablishmentarianism\r\n is very\r\n long.", mail.body.encoded
+ end
+
def test_use_block_format
mail = HelperMailer.use_block_format
expected = <<-TEXT

0 comments on commit 2f9e477

Please sign in to comment.
Something went wrong with that request. Please try again.