Sha256: f4d6358be47442e6335865e6873652e73abeb4875559645335ce8e5222b82b80

Contents?: true

Size: 1.81 KB

Versions: 14

Compression:

Stored size: 1.81 KB

Contents

require "spec_helper"

describe Paperclip::StringioAdapter do
  context "a new instance" do
    before do
      @contents = "abc123"
      @stringio = StringIO.new(@contents)
      @subject = Paperclip.io_adapters.for(@stringio, hash_digest: Digest::MD5)
    end

    it "returns a file name" do
      assert_equal "data", @subject.original_filename
    end

    it "returns a content type" do
      assert_equal "text/plain", @subject.content_type
    end

    it "returns the size of the data" do
      assert_equal 6, @subject.size
    end

    it "returns the length of the data" do
      assert_equal 6, @subject.length
    end

    it "generates an MD5 hash of the contents" do
      assert_equal Digest::MD5.hexdigest(@contents), @subject.fingerprint
    end

    it "generates correct fingerprint after read" do
      fingerprint = Digest::MD5.hexdigest(@subject.read)
      assert_equal fingerprint, @subject.fingerprint
    end

    it "generates same fingerprint" do
      assert_equal @subject.fingerprint, @subject.fingerprint
    end

    it "returns the data contained in the StringIO" do
      assert_equal "abc123", @subject.read
    end

    it "accepts a content_type" do
      @subject.content_type = "image/png"
      assert_equal "image/png", @subject.content_type
    end

    it "accepts an original_filename" do
      @subject.original_filename = "image.png"
      assert_equal "image.png", @subject.original_filename
    end

    it "does not generate filenames that include restricted characters" do
      @subject.original_filename = "image:restricted.png"
      assert_equal "image_restricted.png", @subject.original_filename
    end

    it "does not generate paths that include restricted characters" do
      @subject.original_filename = "image:restricted.png"
      expect(@subject.path).to_not match(/:/)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kt-paperclip-7.2.2 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-7.2.1 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-7.2.0 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-6.4.2 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-7.1.1 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-7.1.0 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-7.0.1 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-7.0.0 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-6.4.1 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-6.4.0 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-6.3.0 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-6.2.2 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-6.2.1 spec/paperclip/io_adapters/stringio_adapter_spec.rb
kt-paperclip-6.2.0 spec/paperclip/io_adapters/stringio_adapter_spec.rb