Fix ActionText::Serialization when dumping an ActionText::RichText

This commit is contained in:
Alexandre Ruban 2021-08-30 21:45:32 +02:00
parent 5aa6083335
commit 458908ed42
2 changed files with 9 additions and 0 deletions

View File

@ -15,6 +15,8 @@ module ActionText
nil
when self
content.to_html
when ActionText::RichText
content.body.to_html
else
new(content).to_html
end

View File

@ -60,6 +60,13 @@ class ActionText::ModelTest < ActiveSupport::TestCase
assert_equal "Hello world", message.content.to_plain_text
end
test "duplicating content" do
message = Message.create!(subject: "Greetings", content: "<b>Hello!</b>")
other_message = Message.create!(subject: "Greetings", content: message.content)
assert_equal message.content.body.to_html, other_message.content.body.to_html
end
test "saving body" do
message = Message.create(subject: "Greetings", body: "<h1>Hello world</h1>")
assert_equal "Hello world", message.body.to_plain_text