diff options
author | George Claghorn <george@basecamp.com> | 2019-03-23 10:04:48 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2019-03-23 10:04:48 -0400 |
commit | ff7948b1c2cbdf5527e40e60a4f2ef7621445d55 (patch) | |
tree | 32a7884e5fc7a4faf3fb6f563afa757a04e3b6ef /actiontext/test | |
parent | 3acf5f71f0a8bbb8d6b2601810f4face5f9291ee (diff) | |
download | rails-ff7948b1c2cbdf5527e40e60a4f2ef7621445d55.tar.gz rails-ff7948b1c2cbdf5527e40e60a4f2ef7621445d55.tar.bz2 rails-ff7948b1c2cbdf5527e40e60a4f2ef7621445d55.zip |
Avoid creating ActionText::RichText records unnecessarily
Assigning a has_one association for a persisted record saves the change immediately, so attempting to read a rich-text attribute on a persisted record without a corresponding ActionText::RichText would eagerly create one. Avoid assigning the rich text association to fix.
Diffstat (limited to 'actiontext/test')
-rw-r--r-- | actiontext/test/unit/model_test.rb | 8 |
1 files changed, 8 insertions, 0 deletions
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 |