mirror of https://github.com/rails/rails
Fix AM format_paragraph helper method if a first word is long
This commit is contained in:
parent
1c75b9afa0
commit
7f33a44ecd
|
@ -41,7 +41,7 @@ module ActionMailer
|
||||||
sentences = [[]]
|
sentences = [[]]
|
||||||
|
|
||||||
text.split.each do |word|
|
text.split.each do |word|
|
||||||
if (sentences.last + [word]).join(' ').length > len
|
if sentences.first.present? && (sentences.last + [word]).join(' ').length > len
|
||||||
sentences << [word]
|
sentences << [word]
|
||||||
else
|
else
|
||||||
sentences.last << word
|
sentences.last << word
|
||||||
|
|
|
@ -22,6 +22,14 @@ class HelperMailer < ActionMailer::Base
|
||||||
end
|
end
|
||||||
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
|
def use_mailer
|
||||||
mail_with_defaults do |format|
|
mail_with_defaults do |format|
|
||||||
format.html { render(:inline => "<%= mailer.message.subject %>") }
|
format.html { render(:inline => "<%= mailer.message.subject %>") }
|
||||||
|
@ -81,6 +89,11 @@ class MailerHelperTest < ActionMailer::TestCase
|
||||||
assert_match " But soft! What\r\n light through\r\n yonder window\r\n breaks?", mail.body.encoded
|
assert_match " But soft! What\r\n light through\r\n yonder window\r\n breaks?", mail.body.encoded
|
||||||
end
|
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
|
def test_use_block_format
|
||||||
mail = HelperMailer.use_block_format
|
mail = HelperMailer.use_block_format
|
||||||
expected = <<-TEXT
|
expected = <<-TEXT
|
||||||
|
|
Loading…
Reference in New Issue