aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actiontext/lib')
-rw-r--r--actiontext/lib/action_text/attachables/remote_image.rb2
-rw-r--r--actiontext/lib/action_text/attachment_gallery.rb2
-rw-r--r--actiontext/lib/action_text/engine.rb11
-rw-r--r--actiontext/lib/action_text/system_test_helper.rb48
4 files changed, 61 insertions, 2 deletions
diff --git a/actiontext/lib/action_text/attachables/remote_image.rb b/actiontext/lib/action_text/attachables/remote_image.rb
index 650b11862b..c5819ef1f5 100644
--- a/actiontext/lib/action_text/attachables/remote_image.rb
+++ b/actiontext/lib/action_text/attachables/remote_image.rb
@@ -14,7 +14,7 @@ module ActionText
private
def content_type_is_image?(content_type)
- content_type.to_s =~ /^image(\/.+|$)/
+ content_type.to_s.match?(/^image(\/.+|$)/)
end
def attributes_from_node(node)
diff --git a/actiontext/lib/action_text/attachment_gallery.rb b/actiontext/lib/action_text/attachment_gallery.rb
index 45afbff058..48ba9f830c 100644
--- a/actiontext/lib/action_text/attachment_gallery.rb
+++ b/actiontext/lib/action_text/attachment_gallery.rb
@@ -23,7 +23,7 @@ module ActionText
Fragment.wrap(content).find_all(SELECTOR).select do |node|
node.children.all? do |child|
if child.text?
- child.text =~ /\A(\n|\ )*\z/
+ /\A(\n|\ )*\z/.match?(child.text)
else
child.matches? ATTACHMENT_SELECTOR
end
diff --git a/actiontext/lib/action_text/engine.rb b/actiontext/lib/action_text/engine.rb
index 51ff5b575b..0f55d460a1 100644
--- a/actiontext/lib/action_text/engine.rb
+++ b/actiontext/lib/action_text/engine.rb
@@ -25,6 +25,10 @@ module ActionText
def previewable_attachable?
representable?
end
+
+ def attachable_plain_text_representation(caption = nil)
+ "[#{caption || filename}]"
+ end
end
end
@@ -46,5 +50,12 @@ module ActionText
before_action { ActionText::Content.renderer = ApplicationController.renderer.new(request.env) }
end
end
+
+ initializer "action_text.system_test_helper" do
+ ActiveSupport.on_load(:action_dispatch_system_test_case) do
+ require "action_text/system_test_helper"
+ include ActionText::SystemTestHelper
+ end
+ end
end
end
diff --git a/actiontext/lib/action_text/system_test_helper.rb b/actiontext/lib/action_text/system_test_helper.rb
new file mode 100644
index 0000000000..77fc9eb50b
--- /dev/null
+++ b/actiontext/lib/action_text/system_test_helper.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module ActionText
+ module SystemTestHelper
+ # Locates a Trix editor and fills it in with the given HTML.
+ #
+ # The editor can be found by:
+ # * its +id+
+ # * its +placeholder+
+ # * its +aria-label+
+ # * the +name+ of its input
+ #
+ # Examples:
+ #
+ # # <trix-editor id="message_content" ...></trix-editor>
+ # fill_in_rich_text_area "message_content", with: "Hello <em>world!</em>"
+ #
+ # # <trix-editor placeholder="Your message here" ...></trix-editor>
+ # fill_in_rich_text_area "Your message here", with: "Hello <em>world!</em>"
+ #
+ # # <trix-editor aria-label="Message content" ...></trix-editor>
+ # fill_in_rich_text_area "Message content", with: "Hello <em>world!</em>"
+ #
+ # # <input id="trix_input_1" name="message[content]" type="hidden">
+ # # <trix-editor input="trix_input_1"></trix-editor>
+ # fill_in_rich_text_area "message[content]", with: "Hello <em>world!</em>"
+ def fill_in_rich_text_area(locator = nil, with:)
+ find(:rich_text_area, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s)
+ end
+ end
+end
+
+Capybara.add_selector :rich_text_area do
+ label "rich-text area"
+ xpath do |locator|
+ if locator.nil?
+ XPath.descendant(:"trix-editor")
+ else
+ input_located_by_name = XPath.anywhere(:input).where(XPath.attr(:name) == locator).attr(:id)
+
+ XPath.descendant(:"trix-editor").where \
+ XPath.attr(:id).equals(locator) |
+ XPath.attr(:placeholder).equals(locator) |
+ XPath.attr(:"aria-label").equals(locator) |
+ XPath.attr(:input).equals(input_located_by_name)
+ end
+ end
+end