Sha256: 0e95fd94ee30b182e0ce35a7f1fc10a3d86172d7e8c8eefcb68b81714dfe3ea9

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

require_relative "../../../test_helper"

class ContentTagsFilesTest < ActiveSupport::TestCase

  setup do
    @page = comfy_cms_pages(:default)
  end

  def url_for(attachment)
    ApplicationController.render(
      inline: "<%= url_for(@attachment) %>",
      assigns: { attachment: attachment }
    )
  end

  # -- Tests -------------------------------------------------------------------

  def test_init
    tag = ComfortableMexicanSofa::Content::Tag::Files.new(@page, "test")
    assert_equal "test",  tag.identifier
    assert_equal "url",   tag.as
  end

  def test_init_with_params
    string = "test, as: image, resize: 100x100, gravity: center, crop: '100x100+0+0'"
    tag = ComfortableMexicanSofa::Content::Tag::Files.new(@page, string)
    assert_equal "test",  tag.identifier
    assert_equal "image", tag.as
    assert_equal ({
      "resize"  => "100x100",
      "gravity" => "center",
      "crop"    => "100x100+0+0"
    }), tag.variant_attrs
  end

  def test_content
    frag = comfy_cms_fragments(:file)
    frag.update_attribute(:tag, "files")
    frag.update_attribute(:files, fixture_file_upload("files/image.jpg", "image/jpeg"))
    tag = ComfortableMexicanSofa::Content::Tag::Files.new(@page, frag.identifier)
    out = frag.attachments.map { |a| url_for(a) }.join(" ")
    assert_equal out, tag.content
  end

  def test_content_no_attachments
    tag = ComfortableMexicanSofa::Content::Tag::Files.new(@page, "test")
    assert_equal "", tag.content
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-2.0.7 test/lib/content/tags/files_test.rb
comfortable_mexican_sofa-2.0.6 test/lib/content/tags/files_test.rb
comfortable_mexican_sofa-2.0.5 test/lib/content/tags/files_test.rb
comfortable_mexican_sofa-2.0.4 test/lib/content/tags/files_test.rb
comfortable_mexican_sofa-2.0.3 test/lib/content/tags/files_test.rb