aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'actiontext/test/unit')
-rw-r--r--actiontext/test/unit/attachment_test.rb8
-rw-r--r--actiontext/test/unit/model_test.rb24
2 files changed, 30 insertions, 2 deletions
diff --git a/actiontext/test/unit/attachment_test.rb b/actiontext/test/unit/attachment_test.rb
index 65e9d69e84..026078dcec 100644
--- a/actiontext/test/unit/attachment_test.rb
+++ b/actiontext/test/unit/attachment_test.rb
@@ -32,7 +32,8 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
assert_equal attachable.byte_size, trix_attachment.attributes["filesize"]
assert_equal "Captioned", trix_attachment.attributes["caption"]
- assert_nil trix_attachment.attributes["content"]
+ assert_not_nil attachable.to_trix_content_attachment_partial_path
+ assert_not_nil trix_attachment.attributes["content"]
end
test "converts to TrixAttachment with content" do
@@ -49,6 +50,11 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
assert_not_nil trix_attachment.attributes["content"]
end
+ test "defaults trix partial to model partial" do
+ attachable = Page.create! title: "Homepage"
+ assert_equal "pages/page", attachable.to_trix_content_attachment_partial_path
+ end
+
private
def attachment_from_html(html)
ActionText::Content.new(html).attachments.first
diff --git a/actiontext/test/unit/model_test.rb b/actiontext/test/unit/model_test.rb
index d56363adc0..af53f88caa 100644
--- a/actiontext/test/unit/model_test.rb
+++ b/actiontext/test/unit/model_test.rb
@@ -49,8 +49,30 @@ class ActionText::ModelTest < ActiveSupport::TestCase
assert_equal "Hello world", message.content.to_plain_text
end
- test "save body" do
+ test "saving body" do
message = Message.create(subject: "Greetings", body: "<h1>Hello world</h1>")
assert_equal "Hello world", message.body.to_plain_text
end
+
+ test "saving content via nested attributes" do
+ message = Message.create! subject: "Greetings", content: "<h1>Hello world</h1>",
+ review_attributes: { author_name: "Marcia", content: "Nice work!" }
+ assert_equal "Nice work!", message.review.content.to_plain_text
+ end
+
+ test "updating content via nested attributes" do
+ message = Message.create! subject: "Greetings", content: "<h1>Hello world</h1>",
+ review_attributes: { author_name: "Marcia", content: "Nice work!" }
+
+ 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