forked from kennon/paperclip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiostream_test.rb
71 lines (57 loc) · 1.91 KB
/
iostream_test.rb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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