aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext
diff options
context:
space:
mode:
Diffstat (limited to 'actiontext')
-rw-r--r--actiontext/app/helpers/action_text/tag_helper.rb4
-rw-r--r--actiontext/test/template/form_helper_test.rb50
-rw-r--r--actiontext/test/test_helper.rb3
3 files changed, 55 insertions, 2 deletions
diff --git a/actiontext/app/helpers/action_text/tag_helper.rb b/actiontext/app/helpers/action_text/tag_helper.rb
index 8434f2c611..1dc6202ae1 100644
--- a/actiontext/app/helpers/action_text/tag_helper.rb
+++ b/actiontext/app/helpers/action_text/tag_helper.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require "action_view/helpers/tags/placeholderable"
+
module ActionText
module TagHelper
cattr_accessor(:id, instance_accessor: false) { 0 }
@@ -35,6 +37,8 @@ end
module ActionView::Helpers
class Tags::ActionText < Tags::Base
+ include Tags::Placeholderable
+
delegate :dom_id, to: ActionView::RecordIdentifier
def render
diff --git a/actiontext/test/template/form_helper_test.rb b/actiontext/test/template/form_helper_test.rb
index a8c7a4dae2..cf7e4c0c69 100644
--- a/actiontext/test/template/form_helper_test.rb
+++ b/actiontext/test/template/form_helper_test.rb
@@ -5,6 +5,26 @@ require "test_helper"
class ActionText::FormHelperTest < ActionView::TestCase
tests ActionText::TagHelper
+ def form_with(*)
+ @output_buffer = super
+ end
+
+ teardown do
+ I18n.backend.reload!
+ end
+
+ setup do
+ I18n.backend.store_translations("placeholder",
+ activerecord: {
+ attributes: {
+ message: {
+ title: "Story title"
+ }
+ }
+ }
+ )
+ end
+
test "form with rich text area" do
form_with model: Message.new, scope: :message do |form|
form.rich_text_area :content
@@ -61,7 +81,33 @@ class ActionText::FormHelperTest < ActionView::TestCase
output_buffer
end
- def form_with(*)
- @output_buffer = super
+ test "form with rich text area having placeholder without locale" do
+ form_with model: Message.new, scope: :message do |form|
+ form.rich_text_area :content, placeholder: true
+ end
+
+ assert_dom_equal \
+ '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \
+ '<input type="hidden" name="message[content]" id="message_content_trix_input_message" />' \
+ '<trix-editor placeholder="Content" id="message_content" input="message_content_trix_input_message" 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/:signed_id/:filename">' \
+ "</trix-editor>" \
+ "</form>",
+ output_buffer
+ end
+
+ test "form with rich text area having placeholder with locale" do
+ I18n.with_locale :placeholder do
+ form_with model: Message.new, scope: :message do |form|
+ form.rich_text_area :title, placeholder: true
+ end
+ end
+
+ assert_dom_equal \
+ '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \
+ '<input type="hidden" name="message[title]" id="message_title_trix_input_message" />' \
+ '<trix-editor placeholder="Story title" id="message_title" input="message_title_trix_input_message" 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/:signed_id/:filename">' \
+ "</trix-editor>" \
+ "</form>",
+ output_buffer
end
end
diff --git a/actiontext/test/test_helper.rb b/actiontext/test/test_helper.rb
index fd1c859349..196fba8c99 100644
--- a/actiontext/test/test_helper.rb
+++ b/actiontext/test/test_helper.rb
@@ -14,6 +14,9 @@ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
require "rails/test_unit/reporter"
Rails::TestUnitReporter.executable = "bin/test"
+# Disable available locale checks to allow to add locale after initialized.
+I18n.enforce_available_locales = false
+
# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)