dm-paperclip 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +29 -0
- data/Gemfile.lock +100 -0
- data/README.md +145 -0
- data/Rakefile +37 -71
- data/VERSION +1 -0
- data/dm-paperclip.gemspec +103 -0
- data/lib/dm-paperclip.rb +88 -74
- data/lib/dm-paperclip/attachment.rb +139 -102
- data/lib/dm-paperclip/callbacks.rb +55 -0
- data/lib/dm-paperclip/command_line.rb +86 -0
- data/lib/dm-paperclip/ext/blank.rb +24 -0
- data/lib/dm-paperclip/ext/class.rb +50 -0
- data/lib/dm-paperclip/ext/compatibility.rb +11 -0
- data/lib/dm-paperclip/ext/try_dup.rb +12 -0
- data/lib/dm-paperclip/geometry.rb +3 -5
- data/lib/dm-paperclip/interpolations.rb +57 -32
- data/lib/dm-paperclip/iostream.rb +12 -26
- data/lib/dm-paperclip/processor.rb +14 -4
- data/lib/dm-paperclip/storage.rb +2 -257
- data/lib/dm-paperclip/storage/filesystem.rb +73 -0
- data/lib/dm-paperclip/storage/s3.rb +209 -0
- data/lib/dm-paperclip/storage/s3/aws_library.rb +41 -0
- data/lib/dm-paperclip/storage/s3/aws_s3_library.rb +60 -0
- data/lib/dm-paperclip/style.rb +90 -0
- data/lib/dm-paperclip/thumbnail.rb +33 -24
- data/lib/dm-paperclip/upfile.rb +13 -5
- data/lib/dm-paperclip/validations.rb +40 -37
- data/lib/dm-paperclip/version.rb +4 -0
- data/test/attachment_test.rb +510 -67
- data/test/command_line_test.rb +138 -0
- data/test/fixtures/s3.yml +8 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/fixtures/uppercase.PNG +0 -0
- data/test/geometry_test.rb +54 -19
- data/test/helper.rb +91 -28
- data/test/integration_test.rb +252 -79
- data/test/interpolations_test.rb +150 -0
- data/test/iostream_test.rb +8 -15
- data/test/paperclip_test.rb +222 -69
- data/test/processor_test.rb +10 -0
- data/test/storage_test.rb +102 -23
- data/test/style_test.rb +141 -0
- data/test/thumbnail_test.rb +106 -18
- data/test/upfile_test.rb +36 -0
- metadata +136 -121
- data/README.rdoc +0 -116
- data/init.rb +0 -1
- data/lib/dm-paperclip/callback_compatability.rb +0 -33
@@ -0,0 +1,10 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class ProcessorTest < Test::Unit::TestCase
|
4
|
+
should "instantiate and call #make when sent #make to the class" do
|
5
|
+
processor = mock
|
6
|
+
processor.expects(:make).with()
|
7
|
+
Paperclip::Processor.expects(:new).with(:one, :two, :three).returns(processor)
|
8
|
+
Paperclip::Processor.make(:one, :two, :three)
|
9
|
+
end
|
10
|
+
end
|
data/test/storage_test.rb
CHANGED
@@ -1,7 +1,32 @@
|
|
1
|
-
require
|
1
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
2
|
+
|
2
3
|
require 'aws/s3'
|
3
4
|
|
4
5
|
class StorageTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "filesystem" do
|
8
|
+
setup do
|
9
|
+
rebuild_model :styles => { :thumbnail => "25x25#" }
|
10
|
+
@dummy = Dummy.create!
|
11
|
+
|
12
|
+
@dummy.avatar = File.open(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
|
13
|
+
end
|
14
|
+
|
15
|
+
should "allow file assignment" do
|
16
|
+
assert @dummy.save
|
17
|
+
end
|
18
|
+
|
19
|
+
should "store the original" do
|
20
|
+
@dummy.save
|
21
|
+
assert File.exists?(@dummy.avatar.path)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "store the thumbnail" do
|
25
|
+
@dummy.save
|
26
|
+
assert File.exists?(@dummy.avatar.path(:thumbnail))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
5
30
|
context "Parsing S3 credentials" do
|
6
31
|
setup do
|
7
32
|
AWS::S3::Base.stubs(:establish_connection!)
|
@@ -12,29 +37,29 @@ class StorageTest < Test::Unit::TestCase
|
|
12
37
|
@dummy = Dummy.new
|
13
38
|
@avatar = @dummy.avatar
|
14
39
|
|
15
|
-
@
|
40
|
+
@old_env = Paperclip.config.env
|
16
41
|
end
|
17
42
|
|
18
43
|
teardown do
|
19
|
-
|
44
|
+
Paperclip.config.env = @old_env
|
20
45
|
end
|
21
46
|
|
22
47
|
should "get the correct credentials when environment is production" do
|
23
|
-
|
48
|
+
Paperclip.config.env = "production"
|
24
49
|
assert_equal({:key => "12345"},
|
25
50
|
@avatar.parse_credentials('production' => {:key => '12345'},
|
26
51
|
:development => {:key => "54321"}))
|
27
52
|
end
|
28
53
|
|
29
54
|
should "get the correct credentials when environment is development" do
|
30
|
-
|
55
|
+
Paperclip.config.env = "development"
|
31
56
|
assert_equal({:key => "54321"},
|
32
57
|
@avatar.parse_credentials('production' => {:key => '12345'},
|
33
58
|
:development => {:key => "54321"}))
|
34
59
|
end
|
35
60
|
|
36
61
|
should "return the argument if the key does not exist" do
|
37
|
-
|
62
|
+
Paperclip.config.env = "not really an env"
|
38
63
|
assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
|
39
64
|
end
|
40
65
|
end
|
@@ -90,7 +115,7 @@ class StorageTest < Test::Unit::TestCase
|
|
90
115
|
assert_match %r{^http://something.something.com/avatars/stringio.txt}, @dummy.avatar.url
|
91
116
|
end
|
92
117
|
end
|
93
|
-
|
118
|
+
|
94
119
|
context "Generating a url with an expiration" do
|
95
120
|
setup do
|
96
121
|
AWS::S3::Base.stubs(:establish_connection!)
|
@@ -102,17 +127,22 @@ class StorageTest < Test::Unit::TestCase
|
|
102
127
|
:s3_host_alias => "something.something.com",
|
103
128
|
:path => ":attachment/:basename.:extension",
|
104
129
|
:url => ":s3_alias_url"
|
105
|
-
|
106
|
-
|
107
|
-
|
130
|
+
|
131
|
+
@old_env = Paperclip.config.env
|
132
|
+
Paperclip.config.env = "production"
|
133
|
+
|
108
134
|
@dummy = Dummy.new
|
109
135
|
@dummy.avatar = StringIO.new(".")
|
110
|
-
|
136
|
+
|
111
137
|
AWS::S3::S3Object.expects(:url_for).with("avatars/stringio.txt", "prod_bucket", { :expires_in => 3600 })
|
112
|
-
|
138
|
+
|
113
139
|
@dummy.avatar.expiring_url
|
114
140
|
end
|
115
|
-
|
141
|
+
|
142
|
+
teardown do
|
143
|
+
Paperclip.config.env = @old_env
|
144
|
+
end
|
145
|
+
|
116
146
|
should "should succeed" do
|
117
147
|
assert true
|
118
148
|
end
|
@@ -127,18 +157,20 @@ class StorageTest < Test::Unit::TestCase
|
|
127
157
|
:development => { :bucket => "dev_bucket" }
|
128
158
|
}
|
129
159
|
@dummy = Dummy.new
|
130
|
-
@old_env =
|
160
|
+
@old_env = Paperclip.config.env
|
131
161
|
end
|
132
162
|
|
133
|
-
teardown
|
163
|
+
teardown do
|
164
|
+
Paperclip.config.env = @old_env
|
165
|
+
end
|
134
166
|
|
135
167
|
should "get the right bucket in production" do
|
136
|
-
|
168
|
+
Paperclip.config.env = "production"
|
137
169
|
assert_equal "prod_bucket", @dummy.avatar.bucket_name
|
138
170
|
end
|
139
171
|
|
140
172
|
should "get the right bucket in development" do
|
141
|
-
|
173
|
+
Paperclip.config.env = "development"
|
142
174
|
assert_equal "dev_bucket", @dummy.avatar.bucket_name
|
143
175
|
end
|
144
176
|
end
|
@@ -187,7 +219,22 @@ class StorageTest < Test::Unit::TestCase
|
|
187
219
|
assert true
|
188
220
|
end
|
189
221
|
end
|
190
|
-
|
222
|
+
|
223
|
+
context "and saved without a bucket" do
|
224
|
+
setup do
|
225
|
+
class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
|
226
|
+
# Force the class to be created as a proper subclass of ResponseError thanks to AWS::S3's autocreation of exceptions
|
227
|
+
end
|
228
|
+
AWS::S3::Bucket.expects(:create).with("testing")
|
229
|
+
AWS::S3::S3Object.stubs(:store).raises(AWS::S3::NoSuchBucket.new(:message, :response)).then.returns(true)
|
230
|
+
@dummy.save
|
231
|
+
end
|
232
|
+
|
233
|
+
should "succeed" do
|
234
|
+
assert true
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
191
238
|
context "and remove" do
|
192
239
|
setup do
|
193
240
|
AWS::S3::S3Object.stubs(:exists?).returns(true)
|
@@ -201,7 +248,7 @@ class StorageTest < Test::Unit::TestCase
|
|
201
248
|
end
|
202
249
|
end
|
203
250
|
end
|
204
|
-
|
251
|
+
|
205
252
|
context "An attachment with S3 storage and bucket defined as a Proc" do
|
206
253
|
setup do
|
207
254
|
AWS::S3::Base.stubs(:establish_connection!)
|
@@ -209,7 +256,7 @@ class StorageTest < Test::Unit::TestCase
|
|
209
256
|
:bucket => lambda { |attachment| "bucket_#{attachment.instance.other}" },
|
210
257
|
:s3_credentials => {:not => :important}
|
211
258
|
end
|
212
|
-
|
259
|
+
|
213
260
|
should "get the right bucket name" do
|
214
261
|
assert "bucket_a", Dummy.new(:other => 'a').avatar.bucket_name
|
215
262
|
assert "bucket_b", Dummy.new(:other => 'b').avatar.bucket_name
|
@@ -257,6 +304,33 @@ class StorageTest < Test::Unit::TestCase
|
|
257
304
|
end
|
258
305
|
end
|
259
306
|
|
307
|
+
context "with S3 credentials supplied as Pathname" do
|
308
|
+
setup do
|
309
|
+
ENV['S3_KEY'] = 'pathname_key'
|
310
|
+
ENV['S3_BUCKET'] = 'pathname_bucket'
|
311
|
+
ENV['S3_SECRET'] = 'pathname_secret'
|
312
|
+
|
313
|
+
@old_env = Paperclip.config.env
|
314
|
+
Paperclip.config.env = 'test'
|
315
|
+
|
316
|
+
rebuild_model :storage => :s3,
|
317
|
+
:s3_credentials => Pathname.new(File.join(File.dirname(__FILE__))).join("fixtures/s3.yml")
|
318
|
+
|
319
|
+
Dummy.auto_migrate!
|
320
|
+
@dummy = Dummy.new
|
321
|
+
end
|
322
|
+
|
323
|
+
teardown do
|
324
|
+
Paperclip.config.env = @old_env
|
325
|
+
end
|
326
|
+
|
327
|
+
should "parse the credentials" do
|
328
|
+
assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
|
329
|
+
assert_equal 'pathname_key', AWS::S3::Base.connection.options[:access_key_id]
|
330
|
+
assert_equal 'pathname_secret', AWS::S3::Base.connection.options[:secret_access_key]
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
260
334
|
context "with S3 credentials in a YAML file" do
|
261
335
|
setup do
|
262
336
|
ENV['S3_KEY'] = 'env_key'
|
@@ -280,7 +354,7 @@ class StorageTest < Test::Unit::TestCase
|
|
280
354
|
end
|
281
355
|
end
|
282
356
|
|
283
|
-
unless ENV["S3_TEST_BUCKET"]
|
357
|
+
unless Paperclip::Ext.blank?(ENV["S3_TEST_BUCKET"])
|
284
358
|
context "Using S3 for real, an attachment with S3 storage" do
|
285
359
|
setup do
|
286
360
|
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
|
@@ -306,7 +380,7 @@ class StorageTest < Test::Unit::TestCase
|
|
306
380
|
teardown { @file.close }
|
307
381
|
|
308
382
|
should "still return a Tempfile when sent #to_file" do
|
309
|
-
assert_equal Tempfile, @dummy.avatar.to_file.class
|
383
|
+
assert_equal Paperclip::Tempfile, @dummy.avatar.to_file.class
|
310
384
|
end
|
311
385
|
|
312
386
|
context "and saved" do
|
@@ -317,8 +391,13 @@ class StorageTest < Test::Unit::TestCase
|
|
317
391
|
should "be on S3" do
|
318
392
|
assert true
|
319
393
|
end
|
394
|
+
|
395
|
+
should "generate a tempfile with the right name" do
|
396
|
+
file = @dummy.avatar.to_file
|
397
|
+
assert_match /^original.*\.png$/, File.basename(file.path)
|
398
|
+
end
|
320
399
|
end
|
321
400
|
end
|
322
401
|
end
|
323
402
|
end
|
324
|
-
end
|
403
|
+
end
|
data/test/style_test.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require './test/helper'
|
3
|
+
|
4
|
+
class StyleTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "A style rule" do
|
7
|
+
setup do
|
8
|
+
@attachment = attachment :path => ":basename.:extension",
|
9
|
+
:styles => { :foo => {:geometry => "100x100#", :format => :png} }
|
10
|
+
@style = @attachment.styles[:foo]
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be held as a Style object" do
|
14
|
+
assert_kind_of Paperclip::Style, @style
|
15
|
+
end
|
16
|
+
|
17
|
+
should "get processors from the attachment definition" do
|
18
|
+
assert_equal [:thumbnail], @style.processors
|
19
|
+
end
|
20
|
+
|
21
|
+
should "have the right geometry" do
|
22
|
+
assert_equal "100x100#", @style.geometry
|
23
|
+
end
|
24
|
+
|
25
|
+
should "be whiny if the attachment is" do
|
26
|
+
@attachment.expects(:whiny).returns(true)
|
27
|
+
assert @style.whiny?
|
28
|
+
end
|
29
|
+
|
30
|
+
should "respond to hash notation" do
|
31
|
+
assert_equal [:thumbnail], @style[:processors]
|
32
|
+
assert_equal "100x100#", @style[:geometry]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "A style rule with properties supplied as procs" do
|
37
|
+
setup do
|
38
|
+
@attachment = attachment :path => ":basename.:extension",
|
39
|
+
:whiny_thumbnails => true,
|
40
|
+
:processors => lambda {|a| [:test]},
|
41
|
+
:styles => {
|
42
|
+
:foo => lambda{|a| "300x300#"},
|
43
|
+
:bar => {
|
44
|
+
:geometry => lambda{|a| "300x300#"}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
should "defer processing of procs until they are needed" do
|
50
|
+
assert_kind_of Proc, @attachment.styles[:foo].instance_variable_get("@geometry")
|
51
|
+
assert_kind_of Proc, @attachment.styles[:bar].instance_variable_get("@geometry")
|
52
|
+
assert_kind_of Proc, @attachment.instance_variable_get("@processors")
|
53
|
+
end
|
54
|
+
|
55
|
+
should "call procs when they are needed" do
|
56
|
+
assert_equal "300x300#", @attachment.styles[:foo].geometry
|
57
|
+
assert_equal "300x300#", @attachment.styles[:bar].geometry
|
58
|
+
assert_equal [:test], @attachment.styles[:foo].processors
|
59
|
+
assert_equal [:test], @attachment.styles[:bar].processors
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "An attachment with style rules in various forms" do
|
64
|
+
setup do
|
65
|
+
@attachment = attachment :path => ":basename.:extension",
|
66
|
+
:styles => {
|
67
|
+
:aslist => ["100x100", :png],
|
68
|
+
:ashash => {:geometry => "100x100", :format => :png},
|
69
|
+
:asstring => "100x100"
|
70
|
+
}
|
71
|
+
end
|
72
|
+
should "have the right number of styles" do
|
73
|
+
assert_kind_of Hash, @attachment.styles
|
74
|
+
assert_equal 3, @attachment.styles.size
|
75
|
+
end
|
76
|
+
|
77
|
+
should "have styles as Style objects" do
|
78
|
+
[:aslist, :ashash, :aslist].each do |s|
|
79
|
+
assert_kind_of Paperclip::Style, @attachment.styles[s]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
should "have the right geometries" do
|
84
|
+
[:aslist, :ashash, :aslist].each do |s|
|
85
|
+
assert_equal @attachment.styles[s].geometry, "100x100"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
should "have the right formats" do
|
90
|
+
assert_equal @attachment.styles[:aslist].format, :png
|
91
|
+
assert_equal @attachment.styles[:ashash].format, :png
|
92
|
+
assert_nil @attachment.styles[:asstring].format
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
context "An attachment with :convert_options" do
|
98
|
+
setup do
|
99
|
+
@attachment = attachment :path => ":basename.:extension",
|
100
|
+
:styles => {:thumb => "100x100", :large => "400x400"},
|
101
|
+
:convert_options => {:all => "-do_stuff", :thumb => "-thumbnailize"}
|
102
|
+
@style = @attachment.styles[:thumb]
|
103
|
+
@file = StringIO.new("...")
|
104
|
+
@file.stubs(:original_filename).returns("file.jpg")
|
105
|
+
end
|
106
|
+
|
107
|
+
before_should "not have called extra_options_for(:thumb/:large) on initialization" do
|
108
|
+
@attachment.expects(:extra_options_for).never
|
109
|
+
end
|
110
|
+
|
111
|
+
should "call extra_options_for(:thumb/:large) when convert options are requested" do
|
112
|
+
@attachment.expects(:extra_options_for).with(:thumb)
|
113
|
+
@attachment.styles[:thumb].convert_options
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "A style rule with its own :processors" do
|
118
|
+
setup do
|
119
|
+
@attachment = attachment :path => ":basename.:extension",
|
120
|
+
:styles => {
|
121
|
+
:foo => {
|
122
|
+
:geometry => "100x100#",
|
123
|
+
:format => :png,
|
124
|
+
:processors => [:test]
|
125
|
+
}
|
126
|
+
},
|
127
|
+
:processors => [:thumbnail]
|
128
|
+
@style = @attachment.styles[:foo]
|
129
|
+
end
|
130
|
+
|
131
|
+
should "not get processors from the attachment" do
|
132
|
+
@attachment.expects(:processors).never
|
133
|
+
assert_not_equal [:thumbnail], @style.processors
|
134
|
+
end
|
135
|
+
|
136
|
+
should "report its own processors" do
|
137
|
+
assert_equal [:test], @style.processors
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
data/test/thumbnail_test.rb
CHANGED
@@ -4,14 +4,15 @@ require 'shoulda'
|
|
4
4
|
require 'mocha'
|
5
5
|
require 'tempfile'
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require 'dm-paperclip/geometry'
|
8
|
+
require 'dm-paperclip/processor'
|
9
|
+
require 'dm-paperclip/thumbnail'
|
9
10
|
|
10
11
|
class ThumbnailTest < Test::Unit::TestCase
|
11
12
|
|
12
13
|
context "A Paperclip Tempfile" do
|
13
14
|
setup do
|
14
|
-
@tempfile = Paperclip::Tempfile.new("file.jpg")
|
15
|
+
@tempfile = Paperclip::Tempfile.new(["file", ".jpg"])
|
15
16
|
end
|
16
17
|
|
17
18
|
should "have its path contain a real extension" do
|
@@ -39,9 +40,11 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
39
40
|
|
40
41
|
context "An image" do
|
41
42
|
setup do
|
42
|
-
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
|
43
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
|
43
44
|
end
|
44
45
|
|
46
|
+
teardown { @file.close }
|
47
|
+
|
45
48
|
[["600x600>", "434x66"],
|
46
49
|
["400x400>", "400x61"],
|
47
50
|
["32x32<", "434x66"]
|
@@ -52,7 +55,7 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
52
55
|
end
|
53
56
|
|
54
57
|
should "start with dimensions of 434x66" do
|
55
|
-
cmd = %Q[identify -format "%wx%h" #{@file.path}]
|
58
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
56
59
|
assert_equal "434x66", `#{cmd}`.chomp
|
57
60
|
end
|
58
61
|
|
@@ -66,7 +69,7 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
66
69
|
end
|
67
70
|
|
68
71
|
should "be the size we expect it to be" do
|
69
|
-
cmd = %Q[identify -format "%wx%h" #{@thumb_result.path}]
|
72
|
+
cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
|
70
73
|
assert_equal args[1], `#{cmd}`.chomp
|
71
74
|
end
|
72
75
|
end
|
@@ -87,7 +90,7 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
87
90
|
assert_nil @thumb.format
|
88
91
|
end
|
89
92
|
|
90
|
-
should "have
|
93
|
+
should "have whiny turned on by default" do
|
91
94
|
assert @thumb.whiny
|
92
95
|
end
|
93
96
|
|
@@ -96,44 +99,84 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
96
99
|
end
|
97
100
|
|
98
101
|
should "send the right command to convert when sent #make" do
|
99
|
-
Paperclip.expects(:
|
100
|
-
|
101
|
-
arg.match %r{"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
|
102
|
+
Paperclip::CommandLine.expects(:"`").with do |arg|
|
103
|
+
arg.match %r{convert ["']#{File.expand_path(@thumb.file.path)}\[0\]["'] -resize ["']x50["'] -crop ["']100x50\+114\+0["'] \+repage ["'].*?["']}
|
102
104
|
end
|
103
105
|
@thumb.make
|
104
106
|
end
|
105
107
|
|
106
108
|
should "create the thumbnail when sent #make" do
|
107
109
|
dst = @thumb.make
|
108
|
-
assert_match /100x50/, `identify #{dst.path}`
|
110
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "being thumbnailed with source file options set" do
|
115
|
+
setup do
|
116
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
117
|
+
:geometry => "100x50#",
|
118
|
+
:source_file_options => "-strip")
|
119
|
+
end
|
120
|
+
|
121
|
+
should "have source_file_options value set" do
|
122
|
+
assert_equal ["-strip"], @thumb.source_file_options
|
123
|
+
end
|
124
|
+
|
125
|
+
should "send the right command to convert when sent #make" do
|
126
|
+
Paperclip::CommandLine.expects(:"`").with do |arg|
|
127
|
+
arg.match %r{convert -strip ["']#{File.expand_path(@thumb.file.path)}\[0\]["'] -resize ["']x50["'] -crop ["']100x50\+114\+0["'] \+repage ["'].*?["']}
|
128
|
+
end
|
129
|
+
@thumb.make
|
130
|
+
end
|
131
|
+
|
132
|
+
should "create the thumbnail when sent #make" do
|
133
|
+
dst = @thumb.make
|
134
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
135
|
+
end
|
136
|
+
|
137
|
+
context "redefined to have bad source_file_options setting" do
|
138
|
+
setup do
|
139
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
140
|
+
:geometry => "100x50#",
|
141
|
+
:source_file_options => "-this-aint-no-option")
|
142
|
+
end
|
143
|
+
|
144
|
+
should "error when trying to create the thumbnail" do
|
145
|
+
assert_raises(Paperclip::PaperclipError) do
|
146
|
+
@thumb.make
|
147
|
+
end
|
148
|
+
end
|
109
149
|
end
|
110
150
|
end
|
111
151
|
|
112
152
|
context "being thumbnailed with convert options set" do
|
113
153
|
setup do
|
114
|
-
@thumb = Paperclip::Thumbnail.new(@file,
|
154
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
155
|
+
:geometry => "100x50#",
|
156
|
+
:convert_options => "-strip -depth 8")
|
115
157
|
end
|
116
158
|
|
117
159
|
should "have convert_options value set" do
|
118
|
-
assert_equal "-strip -depth 8", @thumb.convert_options
|
160
|
+
assert_equal %w"-strip -depth 8", @thumb.convert_options
|
119
161
|
end
|
120
162
|
|
121
163
|
should "send the right command to convert when sent #make" do
|
122
|
-
Paperclip.expects(:
|
123
|
-
|
124
|
-
arg.match %r{"#{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+".*?"}
|
164
|
+
Paperclip::CommandLine.expects(:"`").with do |arg|
|
165
|
+
arg.match %r{convert ["']#{File.expand_path(@thumb.file.path)}\[0\]["'] -resize ["']x50["'] -crop ["']100x50\+114\+0["'] \+repage -strip -depth 8 ["'].*?["']}
|
125
166
|
end
|
126
167
|
@thumb.make
|
127
168
|
end
|
128
169
|
|
129
170
|
should "create the thumbnail when sent #make" do
|
130
171
|
dst = @thumb.make
|
131
|
-
assert_match /100x50/, `identify #{dst.path}`
|
172
|
+
assert_match /100x50/, `identify "#{dst.path}"`
|
132
173
|
end
|
133
174
|
|
134
175
|
context "redefined to have bad convert_options setting" do
|
135
176
|
setup do
|
136
|
-
@thumb = Paperclip::Thumbnail.new(@file,
|
177
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
178
|
+
:geometry => "100x50#",
|
179
|
+
:convert_options => "-this-aint-no-option")
|
137
180
|
end
|
138
181
|
|
139
182
|
should "error when trying to create the thumbnail" do
|
@@ -143,5 +186,50 @@ class ThumbnailTest < Test::Unit::TestCase
|
|
143
186
|
end
|
144
187
|
end
|
145
188
|
end
|
189
|
+
|
190
|
+
context "being thumbnailed with a blank geometry string" do
|
191
|
+
setup do
|
192
|
+
@thumb = Paperclip::Thumbnail.new(@file,
|
193
|
+
:geometry => "",
|
194
|
+
:convert_options => "-gravity center -crop \"300x300+0-0\"")
|
195
|
+
end
|
196
|
+
|
197
|
+
should "not get resized by default" do
|
198
|
+
assert !@thumb.transformation_command.include?("-resize")
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "A multipage PDF" do
|
204
|
+
setup do
|
205
|
+
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb')
|
206
|
+
end
|
207
|
+
|
208
|
+
teardown { @file.close }
|
209
|
+
|
210
|
+
should "start with two pages with dimensions 612x792" do
|
211
|
+
cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
|
212
|
+
assert_equal "612x792"*2, `#{cmd}`.chomp
|
213
|
+
end
|
214
|
+
|
215
|
+
context "being thumbnailed at 100x100 with cropping" do
|
216
|
+
setup do
|
217
|
+
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
|
218
|
+
end
|
219
|
+
|
220
|
+
should "report its correct current and target geometries" do
|
221
|
+
assert_equal "100x100#", @thumb.target_geometry.to_s
|
222
|
+
assert_equal "612x792", @thumb.current_geometry.to_s
|
223
|
+
end
|
224
|
+
|
225
|
+
should "report its correct format" do
|
226
|
+
assert_equal :png, @thumb.format
|
227
|
+
end
|
228
|
+
|
229
|
+
should "create the thumbnail when sent #make" do
|
230
|
+
dst = @thumb.make
|
231
|
+
assert_match /100x100/, `identify "#{dst.path}"`
|
232
|
+
end
|
233
|
+
end
|
146
234
|
end
|
147
235
|
end
|