diff options
Diffstat (limited to 'actiontext')
-rw-r--r-- | actiontext/lib/action_text/attribute.rb | 2 | ||||
-rw-r--r-- | actiontext/test/test_helper.rb | 2 | ||||
-rw-r--r-- | actiontext/test/unit/model_test.rb | 8 |
3 files changed, 11 insertions, 1 deletions
diff --git a/actiontext/lib/action_text/attribute.rb b/actiontext/lib/action_text/attribute.rb index f9a604096c..ddc6822a4c 100644 --- a/actiontext/lib/action_text/attribute.rb +++ b/actiontext/lib/action_text/attribute.rb @@ -26,7 +26,7 @@ module ActionText def has_rich_text(name) class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name} - self.rich_text_#{name} ||= ActionText::RichText.new(name: "#{name}", record: self) + rich_text_#{name} || build_rich_text_#{name} end def #{name}=(body) diff --git a/actiontext/test/test_helper.rb b/actiontext/test/test_helper.rb index 196fba8c99..51a207f76a 100644 --- a/actiontext/test/test_helper.rb +++ b/actiontext/test/test_helper.rb @@ -31,3 +31,5 @@ class ActiveSupport::TestCase ActiveStorage::Blob.create_after_upload! io: file_fixture(filename).open, filename: filename, content_type: content_type, metadata: metadata end end + +require_relative "../../tools/test_common" diff --git a/actiontext/test/unit/model_test.rb b/actiontext/test/unit/model_test.rb index f4328ba2ce..af53f88caa 100644 --- a/actiontext/test/unit/model_test.rb +++ b/actiontext/test/unit/model_test.rb @@ -67,4 +67,12 @@ class ActionText::ModelTest < ActiveSupport::TestCase message.update! review_attributes: { id: message.review.id, content: "Great work!" } assert_equal "Great work!", message.review.reload.content.to_plain_text end + + test "building content lazily on existing record" do + message = Message.create!(subject: "Greetings") + + assert_no_difference -> { ActionText::RichText.count } do + assert_kind_of ActionText::RichText, message.content + end + end end |