From ba97db849cd34a83c05234572d3d7261864c1782 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Sat, 6 Oct 2018 12:11:10 -0400 Subject: Add template for ActionText::Attachables::RemoteImage Fixes #15 --- .../action_text/attachables/_remote_image.html.erb | 8 +++++ test/unit/content_test.rb | 37 +++++++++++++--------- 2 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 app/views/action_text/attachables/_remote_image.html.erb diff --git a/app/views/action_text/attachables/_remote_image.html.erb b/app/views/action_text/attachables/_remote_image.html.erb new file mode 100644 index 0000000000..3372f8d940 --- /dev/null +++ b/app/views/action_text/attachables/_remote_image.html.erb @@ -0,0 +1,8 @@ +
+ <%= image_tag(remote_image.url, width: remote_image.width, height: remote_image.height) %> + <% if caption = remote_image.try(:caption) %> +
+ <%= caption %> +
+ <% end %> +
diff --git a/test/unit/content_test.rb b/test/unit/content_test.rb index c0b8ad024c..dada9cc714 100644 --- a/test/unit/content_test.rb +++ b/test/unit/content_test.rb @@ -3,25 +3,25 @@ require 'test_helper' class ActionText::ContentTest < ActiveSupport::TestCase test "equality" do html = %Q(
test
) - content = ActionText::Content.new(html) - assert_equal content, ActionText::Content.new(html) + content = content_from_html(html) + assert_equal content, content_from_html(html) assert_not_equal content, html end test "marshal serialization" do - content = ActionText::Content.new("Hello!") + content = content_from_html("Hello!") assert_equal content, Marshal.load(Marshal.dump(content)) end test "roundtrips HTML without additional newlines" do html = %Q(
a
) - content = ActionText::Content.new(html) + content = content_from_html(html) assert_equal html, content.to_html end test "extracts links" do html = %Q(1
1) - content = ActionText::Content.new(html) + content = content_from_html(html) assert_equal ["http://example.com/1"], content.links end @@ -29,7 +29,7 @@ class ActionText::ContentTest < ActiveSupport::TestCase attachable = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg") html = %Q() - content = ActionText::Content.new(html) + content = content_from_html(html) assert_equal 1, content.attachments.size attachment = content.attachments.first @@ -40,7 +40,7 @@ class ActionText::ContentTest < ActiveSupport::TestCase test "extracts remote image attachables" do html = %Q() - content = ActionText::Content.new(html) + content = content_from_html(html) assert_equal 1, content.attachments.size attachment = content.attachments.first @@ -57,51 +57,58 @@ class ActionText::ContentTest < ActiveSupport::TestCase attachable = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg") html = %Q() attachable.destroy! - content = ActionText::Content.new(html) + content = content_from_html(html) assert_equal 1, content.attachments.size assert_equal ActionText::Attachables::MissingAttachable, content.attachments.first.attachable end test "extracts missing attachables" do html = %Q() - content = ActionText::Content.new(html) + content = content_from_html(html) assert_equal 1, content.attachments.size assert_equal ActionText::Attachables::MissingAttachable, content.attachments.first.attachable end test "converts Trix-formatted attachments" do html = %Q(
) - content = ActionText::Content.new(html) + content = content_from_html(html) assert_equal 1, content.attachments.size assert_equal %Q(), content.to_html end test "ignores Trix-formatted attachments with malformed JSON" do html = %Q(
) - content = ActionText::Content.new(html) + content = content_from_html(html) assert_equal 0, content.attachments.size end test "minifies attachment markup" do html = %Q(
HTML
) - assert_equal %Q(), ActionText::Content.new(html).to_html + assert_equal %Q(), content_from_html(html).to_html end test "canonicalizes attachment gallery markup" do attachment_html = %Q() html = %Q() - assert_equal %Q(
#{attachment_html}
), ActionText::Content.new(html).to_html + assert_equal %Q(
#{attachment_html}
), content_from_html(html).to_html end test "canonicalizes attachment gallery markup with whitespace" do attachment_html = %Q(\n \n \n) html = %Q() - assert_equal %Q(
#{attachment_html}
), ActionText::Content.new(html).to_html + assert_equal %Q(
#{attachment_html}
), content_from_html(html).to_html end test "canonicalizes nested attachment gallery markup" do attachment_html = %Q() html = %Q(
) - assert_equal %Q(
#{attachment_html}
), ActionText::Content.new(html).to_html + assert_equal %Q(
#{attachment_html}
), content_from_html(html).to_html end + + private + def content_from_html(html) + ActionText::Content.new(html).tap do |content| + assert_nothing_raised { content.to_s } + end + end end -- cgit v1.2.3