dm-paperclip 2.1.2.1 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{README.textile → README.rdoc} +9 -7
- data/Rakefile +5 -5
- data/lib/dm-paperclip.rb +36 -20
- data/lib/dm-paperclip/attachment.rb +81 -23
- data/lib/dm-paperclip/geometry.rb +1 -1
- data/lib/dm-paperclip/iostream.rb +1 -1
- data/lib/dm-paperclip/storage.rb +82 -7
- data/lib/dm-paperclip/thumbnail.rb +16 -8
- data/lib/dm-paperclip/upfile.rb +8 -5
- data/lib/dm-paperclip/validations.rb +5 -5
- data/test/attachment_test.rb +363 -0
- data/test/{test_geometry.rb → geometry_test.rb} +0 -0
- data/test/helper.rb +10 -18
- data/test/{test_integration.rb → integration_test.rb} +73 -11
- data/test/{test_iostream.rb → iostream_test.rb} +0 -0
- data/test/{test_paperclip.rb → paperclip_test.rb} +60 -16
- data/test/{test_storage.rb → storage_test.rb} +38 -1
- data/test/{test_thumbnail.rb → thumbnail_test.rb} +39 -1
- metadata +15 -21
- data/test/test_attachment.rb +0 -225
data/test/test_attachment.rb
DELETED
@@ -1,225 +0,0 @@
|
|
1
|
-
require 'test/helper'
|
2
|
-
|
3
|
-
class Dummy
|
4
|
-
# This is a dummy class
|
5
|
-
end
|
6
|
-
|
7
|
-
class AttachmentTest < Test::Unit::TestCase
|
8
|
-
context "Attachment default_options" do
|
9
|
-
setup do
|
10
|
-
rebuild_model
|
11
|
-
@old_default_options = Paperclip::Attachment.default_options.dup
|
12
|
-
@new_default_options = @old_default_options.merge({
|
13
|
-
:path => "argle/bargle",
|
14
|
-
:url => "fooferon",
|
15
|
-
:default_url => "not here.png"
|
16
|
-
})
|
17
|
-
end
|
18
|
-
|
19
|
-
teardown do
|
20
|
-
Paperclip::Attachment.default_options.merge! @old_default_options
|
21
|
-
end
|
22
|
-
|
23
|
-
should "be overrideable" do
|
24
|
-
Paperclip::Attachment.default_options.merge!(@new_default_options)
|
25
|
-
@new_default_options.keys.each do |key|
|
26
|
-
assert_equal @new_default_options[key],
|
27
|
-
Paperclip::Attachment.default_options[key]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "without an Attachment" do
|
32
|
-
setup do
|
33
|
-
@dummy = Dummy.new
|
34
|
-
end
|
35
|
-
|
36
|
-
should "return false when asked exists?" do
|
37
|
-
assert !@dummy.avatar.exists?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "on an Attachment" do
|
42
|
-
setup do
|
43
|
-
@dummy = Dummy.new
|
44
|
-
@attachment = @dummy.avatar
|
45
|
-
end
|
46
|
-
|
47
|
-
Paperclip::Attachment.default_options.keys.each do |key|
|
48
|
-
should "be the default_options for #{key}" do
|
49
|
-
assert_equal @old_default_options[key],
|
50
|
-
@attachment.instance_variable_get("@#{key}"),
|
51
|
-
key
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "when redefined" do
|
56
|
-
setup do
|
57
|
-
Paperclip::Attachment.default_options.merge!(@new_default_options)
|
58
|
-
@dummy = Dummy.new
|
59
|
-
@attachment = @dummy.avatar
|
60
|
-
end
|
61
|
-
|
62
|
-
Paperclip::Attachment.default_options.keys.each do |key|
|
63
|
-
should "be the new default_options for #{key}" do
|
64
|
-
assert_equal @new_default_options[key],
|
65
|
-
@attachment.instance_variable_get("@#{key}"),
|
66
|
-
key
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "An attachment with similarly named interpolations" do
|
74
|
-
setup do
|
75
|
-
rebuild_model :path => ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
|
76
|
-
@dummy = Dummy.new
|
77
|
-
@dummy.stubs(:id).returns(1024)
|
78
|
-
@file = File.new(File.join(File.dirname(__FILE__),
|
79
|
-
"fixtures",
|
80
|
-
"5k.png"))
|
81
|
-
@dummy.avatar = @file
|
82
|
-
end
|
83
|
-
|
84
|
-
should "make sure that they are interpolated correctly" do
|
85
|
-
assert_equal "1024.omg/1024-bbq/1024what/000/001/024.wtf", @dummy.avatar.path
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "An attachment" do
|
90
|
-
setup do
|
91
|
-
Paperclip::Attachment.default_options.merge!({
|
92
|
-
:path => ":merb_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
|
93
|
-
})
|
94
|
-
FileUtils.rm_rf("tmp")
|
95
|
-
@instance = stub
|
96
|
-
@instance.stubs(:id).returns(41)
|
97
|
-
@instance.stubs(:class).returns(Dummy)
|
98
|
-
@instance.stubs(:attribute_get).with(:test_file_name).returns(nil)
|
99
|
-
@attachment = Paperclip::Attachment.new(:test,
|
100
|
-
@instance)
|
101
|
-
@file = File.new(File.join(File.dirname(__FILE__),
|
102
|
-
"fixtures",
|
103
|
-
"5k.png"))
|
104
|
-
end
|
105
|
-
|
106
|
-
should "return its default_url when no file assigned" do
|
107
|
-
assert @attachment.to_file.nil?
|
108
|
-
assert_equal "/tests/original/missing.png", @attachment.url
|
109
|
-
assert_equal "/tests/blah/missing.png", @attachment.url(:blah)
|
110
|
-
end
|
111
|
-
|
112
|
-
context "with a file assigned in the database" do
|
113
|
-
setup do
|
114
|
-
@instance.stubs(:attribute_get).with(:test_file_name).returns('5k.png')
|
115
|
-
end
|
116
|
-
|
117
|
-
should "return a correct url even if the file does not exist" do
|
118
|
-
assert_nil @attachment.to_file
|
119
|
-
assert_equal "/tests/41/blah/5k.png", @attachment.url(:blah)
|
120
|
-
end
|
121
|
-
|
122
|
-
should "return the proper path when filename has a single .'s" do
|
123
|
-
assert_equal "./test/../tmp/tests/dummies/original/41/5k.png", @attachment.path
|
124
|
-
end
|
125
|
-
|
126
|
-
should "return the proper path when filename has multiple .'s" do
|
127
|
-
@instance.stubs(:attribute_get).with(:test_file_name).returns("5k.old.png")
|
128
|
-
assert_equal "./test/../tmp/tests/dummies/original/41/5k.old.png", @attachment.path
|
129
|
-
end
|
130
|
-
|
131
|
-
context "when expecting three styles" do
|
132
|
-
setup do
|
133
|
-
styles = {:styles => { :large => ["400x400", :png],
|
134
|
-
:medium => ["100x100", :gif],
|
135
|
-
:small => ["32x32#", :jpg]}}
|
136
|
-
@attachment = Paperclip::Attachment.new(:test,
|
137
|
-
@instance,
|
138
|
-
styles)
|
139
|
-
end
|
140
|
-
|
141
|
-
context "and assigned a file" do
|
142
|
-
setup do
|
143
|
-
@instance.expects(:update_attributes).with({ :test_file_name => nil,
|
144
|
-
:test_content_type => nil,
|
145
|
-
:test_file_size => nil })
|
146
|
-
@instance.expects(:update_attributes).with( { :test_file_name => File.basename(@file.path),
|
147
|
-
:test_content_type => "image/png",
|
148
|
-
:test_file_size => @file.size })
|
149
|
-
@attachment.assign(@file)
|
150
|
-
end
|
151
|
-
|
152
|
-
should "be dirty" do
|
153
|
-
assert @attachment.dirty?
|
154
|
-
end
|
155
|
-
|
156
|
-
context "and saved" do
|
157
|
-
setup do
|
158
|
-
@attachment.save
|
159
|
-
end
|
160
|
-
|
161
|
-
should "return the real url" do
|
162
|
-
assert @attachment.to_file
|
163
|
-
assert_equal "/tests/41/original/5k.png", @attachment.url
|
164
|
-
assert_equal "/tests/41/small/5k.jpg", @attachment.url(:small)
|
165
|
-
end
|
166
|
-
|
167
|
-
should "commit the files to disk" do
|
168
|
-
[:large, :medium, :small].each do |style|
|
169
|
-
io = @attachment.to_io(style)
|
170
|
-
assert File.exists?(io)
|
171
|
-
assert ! io.is_a?(::Tempfile)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
should "save the files as the right formats and sizes" do
|
176
|
-
[[:large, 400, 61, "PNG"],
|
177
|
-
[:medium, 100, 15, "GIF"],
|
178
|
-
[:small, 32, 32, "JPEG"]].each do |style|
|
179
|
-
cmd = "identify -format '%w %h %b %m' " +
|
180
|
-
"#{@attachment.to_io(style.first).path}"
|
181
|
-
out = `#{cmd}`
|
182
|
-
width, height, size, format = out.split(" ")
|
183
|
-
assert_equal style[1].to_s, width.to_s
|
184
|
-
assert_equal style[2].to_s, height.to_s
|
185
|
-
assert_equal style[3].to_s, format.to_s
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
should "still have its #file attribute not be nil" do
|
190
|
-
assert ! @attachment.to_file.nil?
|
191
|
-
end
|
192
|
-
|
193
|
-
context "and deleted" do
|
194
|
-
setup do
|
195
|
-
@existing_names = @attachment.styles.keys.collect do |style|
|
196
|
-
@attachment.path(style)
|
197
|
-
end
|
198
|
-
@instance.expects(:update_attributes).with({ :test_file_name => nil,
|
199
|
-
:test_content_type => nil,
|
200
|
-
:test_file_size => nil })
|
201
|
-
@attachment.assign nil
|
202
|
-
@attachment.save
|
203
|
-
end
|
204
|
-
|
205
|
-
should "delete the files" do
|
206
|
-
@existing_names.each{|f| assert ! File.exists?(f) }
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
context "when trying a nonexistant storage type" do
|
216
|
-
setup do
|
217
|
-
rebuild_model :storage => :not_here
|
218
|
-
end
|
219
|
-
|
220
|
-
should "not be able to find the module" do
|
221
|
-
assert_raise(NameError){ Dummy.new.avatar }
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|