Sha256: 1ec2fb8fd5dd94561fdb75e09965e4e8d87d6b760d940f56bfa050c07799c557

Contents?: true

Size: 1.91 KB

Versions: 52

Compression:

Stored size: 1.91 KB

Contents

require './test/helper'

class IOStreamTest < Test::Unit::TestCase
  include IOStream
  context "A file" do
    setup do
      @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
    end

    teardown { @file.close }

    context "that is sent #stream_to" do

      context "and given a String" do
        setup do
          FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
          assert @result = stream_to(@file, File.join(ROOT, 'tmp', 'iostream.string.test'))
        end

        should "return a File" do
          assert @result.is_a?(File)
        end

        should "contain the same data as the original file" do
          @file.rewind; @result.rewind
          assert_equal @file.read, @result.read
        end
      end

      context "and given a Tempfile" do
        setup do
          tempfile = Tempfile.new('iostream.test')
          tempfile.binmode
          assert @result = stream_to(@file, tempfile)
        end

        should "return a Tempfile" do
          assert @result.is_a?(Tempfile)
        end

        should "contain the same data as the original file" do
          @file.rewind; @result.rewind
          assert_equal @file.read, @result.read
        end
      end

    end

    context "that is converted #to_tempfile" do
      setup do
        assert @tempfile = to_tempfile(@file)
      end

      should "convert it to a Paperclip Tempfile" do
        assert @tempfile.is_a?(Paperclip::Tempfile)
      end

      should "have the name be based on the original_filename" do
        name = File.basename(@file.path)
        extension = File.extname(name)
        basename = File.basename(name, extension)
        assert_match %r[^stream.*?#{Regexp.quote(extension)}], File.basename(@tempfile.path)
      end

      should "have the Tempfile contain the same data as the file" do
        @file.rewind; @tempfile.rewind
        assert_equal @file.read, @tempfile.read
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 17 rubygems

Version Path
paperclip-v2_7-patched-ruby-1_8_6-2.7.5 test/iostream_test.rb
paperclip-2.7.5 test/iostream_test.rb
paperclip-2.7.4 test/iostream_test.rb
paperclip-2.7.2 test/iostream_test.rb
paperclip-2.8.0 test/iostream_test.rb
paperclip-2.7.1 test/iostream_test.rb
cloudfuji_paperclip-2.4.6 test/iostream_test.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/paperclip-2.3.16/test/iostream_test.rb
paperclip-2.7.0 test/iostream_test.rb
paperclip-2.6.0 test/iostream_test.rb
paperclip-2.5.2 test/iostream_test.rb
paperclip-2.5.1 test/iostream_test.rb
smarter_paperclip-0.3.0 test/iostream_test.rb
paperclip-2.5.0 test/iostream_test.rb
mender_paperclip-2.4.3.1 test/iostream_test.rb
cemeng-paperclip-2.3.6 test/iostream_test.rb
jmcnevin-paperclip-2.4.5.1 test/iostream_test.rb
jmcnevin-paperclip-2.4.5 test/iostream_test.rb
paperclip-2.4.5 test/iostream_test.rb
mender_paperclip-2.4.3 test/iostream_test.rb