phildarnowsky-paperclip 2.2.10
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/LICENSE +26 -0
- data/README.rdoc +174 -0
- data/Rakefile +99 -0
- data/generators/paperclip/USAGE +5 -0
- data/generators/paperclip/paperclip_generator.rb +27 -0
- data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/init.rb +1 -0
- data/lib/paperclip/attachment.rb +461 -0
- data/lib/paperclip/callback_compatability.rb +33 -0
- data/lib/paperclip/content_type.rb +21 -0
- data/lib/paperclip/geometry.rb +115 -0
- data/lib/paperclip/interpolations.rb +105 -0
- data/lib/paperclip/iostream.rb +58 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +49 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +66 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +48 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +83 -0
- data/lib/paperclip/matchers.rb +4 -0
- data/lib/paperclip/processor.rb +49 -0
- data/lib/paperclip/storage.rb +236 -0
- data/lib/paperclip/thumbnail.rb +70 -0
- data/lib/paperclip/upfile.rb +40 -0
- data/lib/paperclip.rb +360 -0
- data/paperclip.gemspec +37 -0
- data/shoulda_macros/paperclip.rb +68 -0
- data/tasks/paperclip_tasks.rake +79 -0
- data/test/attachment_test.rb +859 -0
- data/test/content_type_test.rb +46 -0
- data/test/database.yml +4 -0
- data/test/fixtures/12k.png +0 -0
- data/test/fixtures/50x50.png +0 -0
- data/test/fixtures/5k.png +0 -0
- data/test/fixtures/bad.png +1 -0
- data/test/fixtures/s3.yml +4 -0
- data/test/fixtures/text.txt +0 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/geometry_test.rb +177 -0
- data/test/helper.rb +100 -0
- data/test/integration_test.rb +484 -0
- data/test/interpolations_test.rb +120 -0
- data/test/iostream_test.rb +71 -0
- data/test/matchers/have_attached_file_matcher_test.rb +21 -0
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +30 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +21 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +50 -0
- data/test/paperclip_test.rb +291 -0
- data/test/processor_test.rb +10 -0
- data/test/storage_test.rb +371 -0
- data/test/thumbnail_test.rb +177 -0
- metadata +127 -0
@@ -0,0 +1,371 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class StorageTest < Test::Unit::TestCase
|
4
|
+
context "Parsing S3 credentials" do
|
5
|
+
setup do
|
6
|
+
rebuild_model :storage => :s3,
|
7
|
+
:bucket => "testing",
|
8
|
+
:s3_credentials => {:not => :important}
|
9
|
+
|
10
|
+
@dummy = Dummy.new
|
11
|
+
@avatar = @dummy.avatar
|
12
|
+
|
13
|
+
@current_env = RAILS_ENV
|
14
|
+
end
|
15
|
+
|
16
|
+
teardown do
|
17
|
+
Object.const_set("RAILS_ENV", @current_env)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "get the correct credentials when RAILS_ENV is production" do
|
21
|
+
Object.const_set('RAILS_ENV', "production")
|
22
|
+
assert_equal({:key => "12345"},
|
23
|
+
@avatar.parse_credentials('production' => {:key => '12345'},
|
24
|
+
:development => {:key => "54321"}))
|
25
|
+
end
|
26
|
+
|
27
|
+
should "get the correct credentials when RAILS_ENV is development" do
|
28
|
+
Object.const_set('RAILS_ENV', "development")
|
29
|
+
assert_equal({:key => "54321"},
|
30
|
+
@avatar.parse_credentials('production' => {:key => '12345'},
|
31
|
+
:development => {:key => "54321"}))
|
32
|
+
end
|
33
|
+
|
34
|
+
should "return the argument if the key does not exist" do
|
35
|
+
Object.const_set('RAILS_ENV', "not really an env")
|
36
|
+
assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "" do
|
41
|
+
setup do
|
42
|
+
rebuild_model :storage => :s3,
|
43
|
+
:s3_credentials => {},
|
44
|
+
:bucket => "bucket",
|
45
|
+
:path => ":attachment/:basename.:extension",
|
46
|
+
:url => ":s3_path_url"
|
47
|
+
@dummy = Dummy.new
|
48
|
+
@dummy.avatar = StringIO.new(".")
|
49
|
+
end
|
50
|
+
|
51
|
+
should "return a url based on an S3 path" do
|
52
|
+
assert_match %r{^http://s3.amazonaws.com/bucket/avatars/stringio.txt}, @dummy.avatar.url
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context "" do
|
56
|
+
setup do
|
57
|
+
rebuild_model :storage => :s3,
|
58
|
+
:s3_credentials => {},
|
59
|
+
:bucket => "bucket",
|
60
|
+
:path => ":attachment/:basename.:extension",
|
61
|
+
:url => ":s3_domain_url"
|
62
|
+
@dummy = Dummy.new
|
63
|
+
@dummy.avatar = StringIO.new(".")
|
64
|
+
end
|
65
|
+
|
66
|
+
should "return a url based on an S3 subdomain" do
|
67
|
+
assert_match %r{^http://bucket.s3.amazonaws.com/avatars/stringio.txt}, @dummy.avatar.url
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "" do
|
71
|
+
setup do
|
72
|
+
rebuild_model :storage => :s3,
|
73
|
+
:s3_credentials => {
|
74
|
+
:production => { :bucket => "prod_bucket" },
|
75
|
+
:development => { :bucket => "dev_bucket" }
|
76
|
+
},
|
77
|
+
:s3_host_alias => "something.something.com",
|
78
|
+
:path => ":attachment/:basename.:extension",
|
79
|
+
:url => ":s3_alias_url"
|
80
|
+
@dummy = Dummy.new
|
81
|
+
@dummy.avatar = StringIO.new(".")
|
82
|
+
end
|
83
|
+
|
84
|
+
should "return a url based on the host_alias" do
|
85
|
+
assert_match %r{^http://something.something.com/avatars/stringio.txt}, @dummy.avatar.url
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "Parsing S3 credentials with a bucket in them" do
|
90
|
+
setup do
|
91
|
+
rebuild_model :storage => :s3,
|
92
|
+
:s3_credentials => {
|
93
|
+
:production => { :bucket => "prod_bucket" },
|
94
|
+
:development => { :bucket => "dev_bucket" }
|
95
|
+
}
|
96
|
+
@dummy = Dummy.new
|
97
|
+
@old_env = RAILS_ENV
|
98
|
+
end
|
99
|
+
|
100
|
+
teardown{ Object.const_set("RAILS_ENV", @old_env) }
|
101
|
+
|
102
|
+
should "get the right bucket in production" do
|
103
|
+
Object.const_set("RAILS_ENV", "production")
|
104
|
+
assert_equal "prod_bucket", @dummy.avatar.bucket_name
|
105
|
+
end
|
106
|
+
|
107
|
+
should "get the right bucket in development" do
|
108
|
+
Object.const_set("RAILS_ENV", "development")
|
109
|
+
assert_equal "dev_bucket", @dummy.avatar.bucket_name
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "An attachment with S3 storage" do
|
114
|
+
setup do
|
115
|
+
rebuild_model :storage => :s3,
|
116
|
+
:bucket => "testing",
|
117
|
+
:path => ":attachment/:style/:basename.:extension",
|
118
|
+
:s3_credentials => {
|
119
|
+
'access_key_id' => "12345",
|
120
|
+
'secret_access_key' => "54321"
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
should "be extended by the S3 module" do
|
125
|
+
assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
|
126
|
+
end
|
127
|
+
|
128
|
+
should "not be extended by the Filesystem module" do
|
129
|
+
assert ! Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem)
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when assigned" do
|
133
|
+
setup do
|
134
|
+
@file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
|
135
|
+
@dummy = Dummy.new
|
136
|
+
@dummy.avatar = @file
|
137
|
+
end
|
138
|
+
|
139
|
+
teardown { @file.close }
|
140
|
+
|
141
|
+
should "not get a bucket to get a URL" do
|
142
|
+
@dummy.avatar.expects(:s3).never
|
143
|
+
@dummy.avatar.expects(:s3_bucket).never
|
144
|
+
assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
|
145
|
+
end
|
146
|
+
|
147
|
+
context "and saved" do
|
148
|
+
setup do
|
149
|
+
@s3_mock = stub
|
150
|
+
@bucket_mock = stub
|
151
|
+
RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
|
152
|
+
@s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
|
153
|
+
@key_mock = stub
|
154
|
+
@bucket_mock.expects(:key).returns(@key_mock)
|
155
|
+
@key_mock.expects(:data=)
|
156
|
+
@key_mock.expects(:put).with(nil, 'public-read', 'Content-type' => 'image/png')
|
157
|
+
@dummy.save
|
158
|
+
end
|
159
|
+
|
160
|
+
should "succeed" do
|
161
|
+
assert true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "and remove" do
|
166
|
+
setup do
|
167
|
+
@s3_mock = stub
|
168
|
+
@bucket_mock = stub
|
169
|
+
RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
|
170
|
+
@s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
|
171
|
+
@key_mock = stub
|
172
|
+
@bucket_mock.expects(:key).at_least(2).returns(@key_mock)
|
173
|
+
@key_mock.expects(:delete)
|
174
|
+
@dummy.destroy_attached_files
|
175
|
+
end
|
176
|
+
|
177
|
+
should "succeed" do
|
178
|
+
assert true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "An attachment with S3 storage and bucket defined as a Proc" do
|
185
|
+
setup do
|
186
|
+
rebuild_model :storage => :s3,
|
187
|
+
:bucket => lambda { |attachment| "bucket_#{attachment.instance.other}" },
|
188
|
+
:s3_credentials => {:not => :important}
|
189
|
+
end
|
190
|
+
|
191
|
+
should "get the right bucket name" do
|
192
|
+
assert "bucket_a", Dummy.new(:other => 'a').avatar.bucket_name
|
193
|
+
assert "bucket_b", Dummy.new(:other => 'b').avatar.bucket_name
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "An attachment with S3 storage and specific s3 headers set" do
|
198
|
+
setup do
|
199
|
+
rebuild_model :storage => :s3,
|
200
|
+
:bucket => "testing",
|
201
|
+
:path => ":attachment/:style/:basename.:extension",
|
202
|
+
:s3_credentials => {
|
203
|
+
'access_key_id' => "12345",
|
204
|
+
'secret_access_key' => "54321"
|
205
|
+
},
|
206
|
+
:s3_headers => {'Cache-Control' => 'max-age=31557600'}
|
207
|
+
end
|
208
|
+
|
209
|
+
context "when assigned" do
|
210
|
+
setup do
|
211
|
+
@file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
|
212
|
+
@dummy = Dummy.new
|
213
|
+
@dummy.avatar = @file
|
214
|
+
end
|
215
|
+
|
216
|
+
teardown { @file.close }
|
217
|
+
|
218
|
+
context "and saved" do
|
219
|
+
setup do
|
220
|
+
@s3_mock = stub
|
221
|
+
@bucket_mock = stub
|
222
|
+
RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
|
223
|
+
@s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
|
224
|
+
@key_mock = stub
|
225
|
+
@bucket_mock.expects(:key).returns(@key_mock)
|
226
|
+
@key_mock.expects(:data=)
|
227
|
+
@key_mock.expects(:put).with(nil,
|
228
|
+
'public-read',
|
229
|
+
'Content-type' => 'image/png',
|
230
|
+
'Cache-Control' => 'max-age=31557600')
|
231
|
+
@dummy.save
|
232
|
+
end
|
233
|
+
|
234
|
+
should "succeed" do
|
235
|
+
assert true
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context "An attachment with S3 storage and a thumbnail style" do
|
242
|
+
setup do
|
243
|
+
rebuild_model :storage => :s3,
|
244
|
+
:bucket => "testing",
|
245
|
+
:path => ":attachment/:style/:basename.:extension",
|
246
|
+
:s3_credentials => {
|
247
|
+
'access_key_id' => "12345",
|
248
|
+
'secret_access_key' => "54321"
|
249
|
+
},
|
250
|
+
:styles => { :thumb => "100x100" }
|
251
|
+
end
|
252
|
+
|
253
|
+
context "when assigned" do
|
254
|
+
setup do
|
255
|
+
@file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
|
256
|
+
@dummy = Dummy.new
|
257
|
+
@dummy.avatar = @file
|
258
|
+
end
|
259
|
+
|
260
|
+
teardown { @file.close }
|
261
|
+
|
262
|
+
context "and saved" do
|
263
|
+
setup do
|
264
|
+
@s3_mock = stub
|
265
|
+
@bucket_mock = stub
|
266
|
+
RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
|
267
|
+
@s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
|
268
|
+
@key_mock = stub
|
269
|
+
@bucket_mock.expects(:key).twice.returns(@key_mock)
|
270
|
+
@key_mock.expects(:data=).twice
|
271
|
+
@key_mock.expects(:put).with(nil,
|
272
|
+
'public-read',
|
273
|
+
'Content-type' => 'image/png').twice
|
274
|
+
@dummy.save
|
275
|
+
end
|
276
|
+
|
277
|
+
should "succeed" do
|
278
|
+
assert true
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
context "An attachment with S3 storage and a thumbnail style with a different format from the original" do
|
285
|
+
setup do
|
286
|
+
rebuild_model :storage => :s3,
|
287
|
+
:bucket => "testing",
|
288
|
+
:path => ":attachment/:style/:basename.:extension",
|
289
|
+
:s3_credentials => {
|
290
|
+
'access_key_id' => "12345",
|
291
|
+
'secret_access_key' => "54321"
|
292
|
+
},
|
293
|
+
:styles => { :thumb => ["100x100", :gif] }
|
294
|
+
end
|
295
|
+
|
296
|
+
context "when assigned" do
|
297
|
+
setup do
|
298
|
+
@file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
|
299
|
+
@dummy = Dummy.new
|
300
|
+
@dummy.avatar = @file
|
301
|
+
end
|
302
|
+
|
303
|
+
teardown { @file.close }
|
304
|
+
|
305
|
+
context "and saved" do
|
306
|
+
setup do
|
307
|
+
@s3_mock = stub
|
308
|
+
@bucket_mock = stub
|
309
|
+
RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
|
310
|
+
@s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
|
311
|
+
@key_mock = stub
|
312
|
+
@bucket_mock.expects(:key).twice.returns(@key_mock)
|
313
|
+
@key_mock.expects(:data=).twice
|
314
|
+
@key_mock.expects(:put).with(nil,
|
315
|
+
'public-read',
|
316
|
+
'Content-type' => 'image/png')
|
317
|
+
@key_mock.expects(:put).with(nil,
|
318
|
+
'public-read',
|
319
|
+
'Content-type' => 'image/gif')
|
320
|
+
@dummy.save
|
321
|
+
end
|
322
|
+
|
323
|
+
should "succeed" do
|
324
|
+
assert true
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
unless ENV["S3_TEST_BUCKET"].blank?
|
331
|
+
context "Using S3 for real, an attachment with S3 storage" do
|
332
|
+
setup do
|
333
|
+
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
|
334
|
+
:storage => :s3,
|
335
|
+
:bucket => ENV["S3_TEST_BUCKET"],
|
336
|
+
:path => ":class/:attachment/:id/:style.:extension",
|
337
|
+
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "s3.yml"))
|
338
|
+
|
339
|
+
Dummy.delete_all
|
340
|
+
@dummy = Dummy.new
|
341
|
+
end
|
342
|
+
|
343
|
+
should "be extended by the S3 module" do
|
344
|
+
assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
|
345
|
+
end
|
346
|
+
|
347
|
+
context "when assigned" do
|
348
|
+
setup do
|
349
|
+
@file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
|
350
|
+
@dummy.avatar = @file
|
351
|
+
end
|
352
|
+
|
353
|
+
teardown { @file.close }
|
354
|
+
|
355
|
+
should "still return a Tempfile when sent #to_io" do
|
356
|
+
assert_equal Tempfile, @dummy.avatar.to_io.class
|
357
|
+
end
|
358
|
+
|
359
|
+
context "and saved" do
|
360
|
+
setup do
|
361
|
+
@dummy.save
|
362
|
+
end
|
363
|
+
|
364
|
+
should "be on S3" do
|
365
|
+
assert true
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class ThumbnailTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A Paperclip Tempfile" do
|
6
|
+
setup do
|
7
|
+
@tempfile = Paperclip::Tempfile.new("file.jpg")
|
8
|
+
end
|
9
|
+
|
10
|
+
should "have its path contain a real extension" do
|
11
|
+
assert_equal ".jpg", File.extname(@tempfile.path)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be a real Tempfile" do
|
15
|
+
assert @tempfile.is_a?(::Tempfile)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "Another Paperclip Tempfile" do
|
20
|
+
setup do
|
21
|
+
@tempfile = Paperclip::Tempfile.new("file")
|
22
|
+
end
|
23
|
+
|
24
|
+
should "not have an extension if not given one" do
|
25
|
+
assert_equal "", File.extname(@tempfile.path)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "still be a real Tempfile" do
|
29
|
+
assert @tempfile.is_a?(::Tempfile)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "An image" do
|
34
|
+
setup do
|
35
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
|
36
|
+
end
|
37
|
+
|
38
|
+
teardown { @file.close }
|
39
|
+
|
40
|
+
[["600x600>", "434x66"],
|
41
|
+
["400x400>", "400x61"],
|
42
|
+
["32x32<", "434x66"]
|
43
|
+
].each do |args|
|
44
|
+
context "being thumbnailed with a geometry of #{args[0]}" do
|
45
|
+
setup do
|
46
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
|
47
|
+
end
|
48
|
+
|
49
|
+
should "start with dimensions of 434x66" do
|
50
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
51
|
+
assert_equal "434x66", `#{cmd}`.chomp
|
52
|
+
end
|
53
|
+
|
54
|
+
should "report the correct target geometry" do
|
55
|
+
assert_equal args[0], @thumb.target_geometry.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when made" do
|
59
|
+
setup do
|
60
|
+
@thumb_result = @thumb.make
|
61
|
+
end
|
62
|
+
|
63
|
+
should "be the size we expect it to be" do
|
64
|
+
cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
|
65
|
+
assert_equal args[1], `#{cmd}`.chomp
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "being thumbnailed at 100x50 with cropping" do
|
72
|
+
setup do
|
73
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
|
74
|
+
end
|
75
|
+
|
76
|
+
should "report its correct current and target geometries" do
|
77
|
+
assert_equal "100x50#", @thumb.target_geometry.to_s
|
78
|
+
assert_equal "434x66", @thumb.current_geometry.to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
should "report its correct format" do
|
82
|
+
assert_nil @thumb.format
|
83
|
+
end
|
84
|
+
|
85
|
+
should "have whiny turned on by default" do
|
86
|
+
assert @thumb.whiny
|
87
|
+
end
|
88
|
+
|
89
|
+
should "have convert_options set to nil by default" do
|
90
|
+
assert_equal nil, @thumb.convert_options
|
91
|
+
end
|
92
|
+
|
93
|
+
should "send the right command to convert when sent #make" do
|
94
|
+
Paperclip.expects(:"`").with do |arg|
|
95
|
+
arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
|
96
|
+
end
|
97
|
+
@thumb.make
|
98
|
+
end
|
99
|
+
|
100
|
+
should "create the thumbnail when sent #make" do
|
101
|
+
dst = @thumb.make
|
102
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "being thumbnailed with convert options set" do
|
107
|
+
setup do
|
108
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
109
|
+
:geometry => "100x50#",
|
110
|
+
:convert_options => "-strip -depth 8")
|
111
|
+
end
|
112
|
+
|
113
|
+
should "have convert_options value set" do
|
114
|
+
assert_equal "-strip -depth 8", @thumb.convert_options
|
115
|
+
end
|
116
|
+
|
117
|
+
should "send the right command to convert when sent #make" do
|
118
|
+
Paperclip.expects(:"`").with do |arg|
|
119
|
+
arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+"x50"\s+-crop\s+"100x50\+114\+0"\s+\+repage\s+-strip\s+-depth\s+8\s+".*?"}
|
120
|
+
end
|
121
|
+
@thumb.make
|
122
|
+
end
|
123
|
+
|
124
|
+
should "create the thumbnail when sent #make" do
|
125
|
+
dst = @thumb.make
|
126
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
127
|
+
end
|
128
|
+
|
129
|
+
context "redefined to have bad convert_options setting" do
|
130
|
+
setup do
|
131
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
132
|
+
:geometry => "100x50#",
|
133
|
+
:convert_options => "-this-aint-no-option")
|
134
|
+
end
|
135
|
+
|
136
|
+
should "error when trying to create the thumbnail" do
|
137
|
+
assert_raises(Paperclip::PaperclipError) do
|
138
|
+
@thumb.make
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "A multipage PDF" do
|
146
|
+
setup do
|
147
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb')
|
148
|
+
end
|
149
|
+
|
150
|
+
teardown { @file.close }
|
151
|
+
|
152
|
+
should "start with two pages with dimensions 612x792" do
|
153
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
154
|
+
assert_equal "612x792"*2, `#{cmd}`.chomp
|
155
|
+
end
|
156
|
+
|
157
|
+
context "being thumbnailed at 100x100 with cropping" do
|
158
|
+
setup do
|
159
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
|
160
|
+
end
|
161
|
+
|
162
|
+
should "report its correct current and target geometries" do
|
163
|
+
assert_equal "100x100#", @thumb.target_geometry.to_s
|
164
|
+
assert_equal "612x792", @thumb.current_geometry.to_s
|
165
|
+
end
|
166
|
+
|
167
|
+
should "report its correct format" do
|
168
|
+
assert_equal :png, @thumb.format
|
169
|
+
end
|
170
|
+
|
171
|
+
should "create the thumbnail when sent #make" do
|
172
|
+
dst = @thumb.make
|
173
|
+
assert_match /100x100/, `identify "#{dst.path}"`
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phildarnowsky-paperclip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.10
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Yurek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-29 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: jyurek@thoughtbot.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- README.rdoc
|
45
|
+
- LICENSE
|
46
|
+
- Rakefile
|
47
|
+
- init.rb
|
48
|
+
- paperclip.gemspec
|
49
|
+
- generators/paperclip
|
50
|
+
- generators/paperclip/paperclip_generator.rb
|
51
|
+
- generators/paperclip/templates
|
52
|
+
- generators/paperclip/templates/paperclip_migration.rb.erb
|
53
|
+
- generators/paperclip/USAGE
|
54
|
+
- lib/paperclip
|
55
|
+
- lib/paperclip/attachment.rb
|
56
|
+
- lib/paperclip/callback_compatability.rb
|
57
|
+
- lib/paperclip/content_type.rb
|
58
|
+
- lib/paperclip/geometry.rb
|
59
|
+
- lib/paperclip/interpolations.rb
|
60
|
+
- lib/paperclip/iostream.rb
|
61
|
+
- lib/paperclip/matchers
|
62
|
+
- lib/paperclip/matchers/have_attached_file_matcher.rb
|
63
|
+
- lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
|
64
|
+
- lib/paperclip/matchers/validate_attachment_presence_matcher.rb
|
65
|
+
- lib/paperclip/matchers/validate_attachment_size_matcher.rb
|
66
|
+
- lib/paperclip/matchers.rb
|
67
|
+
- lib/paperclip/processor.rb
|
68
|
+
- lib/paperclip/storage.rb
|
69
|
+
- lib/paperclip/thumbnail.rb
|
70
|
+
- lib/paperclip/upfile.rb
|
71
|
+
- lib/paperclip.rb
|
72
|
+
- tasks/paperclip_tasks.rake
|
73
|
+
- test/attachment_test.rb
|
74
|
+
- test/content_type_test.rb
|
75
|
+
- test/database.yml
|
76
|
+
- test/fixtures
|
77
|
+
- test/fixtures/12k.png
|
78
|
+
- test/fixtures/50x50.png
|
79
|
+
- test/fixtures/5k.png
|
80
|
+
- test/fixtures/bad.png
|
81
|
+
- test/fixtures/s3.yml
|
82
|
+
- test/fixtures/text.txt
|
83
|
+
- test/fixtures/twopage.pdf
|
84
|
+
- test/geometry_test.rb
|
85
|
+
- test/helper.rb
|
86
|
+
- test/integration_test.rb
|
87
|
+
- test/interpolations_test.rb
|
88
|
+
- test/iostream_test.rb
|
89
|
+
- test/matchers
|
90
|
+
- test/matchers/have_attached_file_matcher_test.rb
|
91
|
+
- test/matchers/validate_attachment_content_type_matcher_test.rb
|
92
|
+
- test/matchers/validate_attachment_presence_matcher_test.rb
|
93
|
+
- test/matchers/validate_attachment_size_matcher_test.rb
|
94
|
+
- test/paperclip_test.rb
|
95
|
+
- test/processor_test.rb
|
96
|
+
- test/storage_test.rb
|
97
|
+
- test/thumbnail_test.rb
|
98
|
+
- shoulda_macros/paperclip.rb
|
99
|
+
has_rdoc: true
|
100
|
+
homepage: http://www.thoughtbot.com/projects/paperclip
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options:
|
103
|
+
- --line-numbers
|
104
|
+
- --inline-source
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
112
|
+
version:
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: "0"
|
118
|
+
version:
|
119
|
+
requirements:
|
120
|
+
- ImageMagick
|
121
|
+
rubyforge_project: paperclip
|
122
|
+
rubygems_version: 1.2.0
|
123
|
+
signing_key:
|
124
|
+
specification_version: 2
|
125
|
+
summary: File attachments as attributes for ActiveRecord
|
126
|
+
test_files: []
|
127
|
+
|