This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
/
filesystem_test.rb
71 lines (56 loc) · 1.85 KB
/
filesystem_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 FileSystemTest < Test::Unit::TestCase
context "Filesystem" do
context "normal file" do
setup do
rebuild_model :styles => { :thumbnail => "25x25#" }
@dummy = Dummy.create!
@file = File.open(fixture_file('5k.png'))
@dummy.avatar = @file
end
teardown { @file.close }
should "allow file assignment" do
assert @dummy.save
end
should "store the original" do
@dummy.save
assert_file_exists(@dummy.avatar.path)
end
should "store the thumbnail" do
@dummy.save
assert_file_exists(@dummy.avatar.path(:thumbnail))
end
should "be rewinded after flush_writes" do
@dummy.avatar.instance_eval "def after_flush_writes; end"
files = @dummy.avatar.queued_for_write.values
@dummy.save
assert files.none?(&:eof?), "Expect all the files to be rewinded."
end
should "be removed after after_flush_writes" do
paths = @dummy.avatar.queued_for_write.values.map(&:path)
@dummy.save
assert paths.none?{ |path| File.exists?(path) },
"Expect all the files to be deleted."
end
end
context "with file that has space in file name" do
setup do
rebuild_model :styles => { :thumbnail => "25x25#" }
@dummy = Dummy.create!
@file = File.open(fixture_file('spaced file.png'))
@dummy.avatar = @file
@dummy.save
end
teardown { @file.close }
should "store the file" do
assert_file_exists(@dummy.avatar.path)
end
should "return a replaced version for path" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
end
should "return a replaced version for url" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
end
end
end
end