public
Description: Paperclip File Management Plugin
Homepage: http://www.thoughtbot.com/projects/paperclip
Clone URL: git://github.com/thoughtbot/paperclip.git
paperclip / test / iostream_test.rb
100644 55 lines (44 sloc) 1.425 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'test/helper'
 
class IOStreamTest < Test::Unit::TestCase
  context "IOStream" do
    should "be included in IO, File, Tempfile, and StringIO" do
      [IO, File, Tempfile, StringIO].each do |klass|
        assert klass.included_modules.include?(IOStream), "Not in #{klass}"
      end
    end
  end
 
  context "A file" do
    setup do
      @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
    end
 
    context "that is sent #stream_to" do
 
      [["/tmp/iostream.string.test", File],
       [Tempfile.new('iostream.test'), Tempfile]].each do |args|
 
        context "and given a #{args[0].class.to_s}" do
          setup do
            assert @result = @file.stream_to(args[0])
          end
 
          should "return a #{args[1].to_s}" do
            assert @result.is_a?(args[1])
          end
 
          should "contain the same data as the original file" do
            @file.rewind; @result.rewind
            assert_equal @file.read, @result.read
          end
        end
      end
    end
 
    context "that is sent #to_tempfile" do
      setup do
        assert @tempfile = @file.to_tempfile
      end
 
      should "convert it to a Tempfile" do
        assert @tempfile.is_a?(Tempfile)
      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