Skip to content

Commit 16c28d0

Browse files
committed
Add test coverage for rich_text_area helper
Follow-up to [rails#50252][] Similar to the reliance on a `FormBuilder` in the helper methods documentation examples, the template test coverage for `#rich_text_area` relied on invocations through a `FormBuilder` instance. This commit adds explicit coverage for calling the `#rich_text_area` helper method directly with both an `object_name` and `method_name` positional arguments. [rails#50252]: rails#50252
1 parent da871cc commit 16c28d0

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

actiontext/test/template/form_helper_test.rb

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,37 @@ def form_with(*, **)
2525
)
2626
end
2727

28-
test "rich text area tag" do
28+
test "#rich_text_area_tag helper" do
2929
message = Message.new
3030

31-
form_with model: message, scope: :message do |form|
32-
rich_text_area_tag :content, message.content, { input: "trix_input_1" }
33-
end
31+
concat rich_text_area_tag :content, message.content, { input: "trix_input_1" }
3432

3533
assert_dom_equal \
36-
'<form action="/messages" accept-charset="UTF-8" method="post">' \
37-
'<input type="hidden" name="content" id="trix_input_1" autocomplete="off" />' \
38-
'<trix-editor input="trix_input_1" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename">' \
39-
"</trix-editor>" \
40-
"</form>",
34+
'<input type="hidden" name="content" id="trix_input_1" autocomplete="off" />' \
35+
'<trix-editor input="trix_input_1" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename">' \
36+
"</trix-editor>",
37+
output_buffer
38+
end
39+
40+
test "#rich_text_area helper" do
41+
concat rich_text_area :message, :content, input: "trix_input_1"
42+
43+
assert_dom_equal \
44+
'<input type="hidden" name="message[content]" id="trix_input_1" autocomplete="off" />' \
45+
'<trix-editor id="message_content" input="trix_input_1" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename">' \
46+
"</trix-editor>",
47+
output_buffer
48+
end
49+
50+
test "#rich_text_area helper renders the :value argument into the hidden field" do
51+
message = Message.new content: "<h1>hello world</h1>"
52+
53+
concat rich_text_area :message, :title, value: message.content, input: "trix_input_1"
54+
55+
assert_dom_equal \
56+
'<input type="hidden" name="message[title]" id="trix_input_1" value="&lt;h1&gt;hello world&lt;/h1&gt;" autocomplete="off" />' \
57+
'<trix-editor id="message_title" input="trix_input_1" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename">' \
58+
"</trix-editor>",
4159
output_buffer
4260
end
4361

0 commit comments

Comments
 (0)