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) assert_not_equal content, html end test "marshal serialization" do content = ActionText::Content.new("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) assert_equal html, content.to_html end test "extracts links" do html = %Q(1
1) content = ActionText::Content.new(html) assert_equal ["http://example.com/1"], content.links end test "extracts attachables" do attachable = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg") html = %Q() content = ActionText::Content.new(html) assert_equal 1, content.attachments.size attachment = content.attachments.first assert_equal "Captioned", attachment.caption assert_equal attachable, attachment.attachable end test "extracts remote image attachables" do html = %Q() content = ActionText::Content.new(html) assert_equal 1, content.attachments.size attachment = content.attachments.first assert_equal "Captioned", attachment.caption attachable = attachment.attachable assert_kind_of ActionText::Attachables::RemoteImage, attachable assert_equal "http://example.com/cat.jpg", attachable.url assert_equal "100", attachable.width assert_equal "100", attachable.height end test "identifies destroyed attachables as missing" do attachable = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg") html = %Q() attachable.destroy! content = ActionText::Content.new(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) # 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) # 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) # assert_equal 0, content.attachments.size # end # # test "minifies attachment markup" do # html = %Q(
HTML
) # assert_equal %Q(), ActionText::Content.new(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 # 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 # end # # test "canonicalizes nested attachment gallery markup" do # attachment_html = %Q() # html = %Q(
) # assert_equal %Q(
#{attachment_html}
), ActionText::Content.new(html).to_html # end end