From 458908ed4281a662cbc8713f4d61dfb63eac2d5f Mon Sep 17 00:00:00 2001 From: Alexandre Ruban Date: Mon, 30 Aug 2021 21:45:32 +0200 Subject: [PATCH] Fix ActionText::Serialization when dumping an ActionText::RichText --- actiontext/lib/action_text/serialization.rb | 2 ++ actiontext/test/unit/model_test.rb | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/actiontext/lib/action_text/serialization.rb b/actiontext/lib/action_text/serialization.rb index 8ecf8c9157..87578be335 100644 --- a/actiontext/lib/action_text/serialization.rb +++ b/actiontext/lib/action_text/serialization.rb @@ -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 diff --git a/actiontext/test/unit/model_test.rb b/actiontext/test/unit/model_test.rb index 7193a82714..99b4af6b3b 100644 --- a/actiontext/test/unit/model_test.rb +++ b/actiontext/test/unit/model_test.rb @@ -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: "Hello!") + 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: "

Hello world

") assert_equal "Hello world", message.body.to_plain_text