Sha256: b2efee06a5dea52c0e8e397abd89433f9c9945aa2df1e1afe594161726581b10

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

require './test/helper'

class AbstractAdapterTest < Test::Unit::TestCase
  class TestAdapter < Paperclip::AbstractAdapter
    attr_accessor :tempfile

    def content_type
      Paperclip::ContentTypeDetector.new(path).detect
    end
  end

  context "content type from file command" do
    setup do
      @adapter = TestAdapter.new
      @adapter.stubs(:path).returns("image.png")
    end

    should "return the content type without newline" do
      assert_equal "image/png", @adapter.content_type
    end
  end

  context "nil?" do
    should "return false" do
      assert !TestAdapter.new.nil?
    end
  end

  context "delegation" do
    setup do
      @adapter = TestAdapter.new
      @adapter.tempfile = stub("Tempfile")
    end

    [:close, :closed?, :eof?, :path, :rewind, :unlink].each do |method|
      should "delegate #{method} to @tempfile" do
        @adapter.tempfile.stubs(method)
        @adapter.public_send(method)
        assert_received @adapter.tempfile, method
      end
    end
  end

  should 'get rid of slashes and colons in filenames' do
    @adapter = TestAdapter.new
    @adapter.original_filename = "awesome/file:name.png"

    assert_equal "awesome_file_name.png", @adapter.original_filename
  end

  should 'be an assignment' do
    assert TestAdapter.new.assignment?
  end

  should 'not be nil' do
    assert !TestAdapter.new.nil?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
paperclip-3.5.2 test/io_adapters/abstract_adapter_test.rb
paperclip-3.5.1 test/io_adapters/abstract_adapter_test.rb
paperclip-3.5.0 test/io_adapters/abstract_adapter_test.rb