paperclip 2.3.1.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- data/README.rdoc +6 -1
- data/Rakefile +11 -38
- data/generators/paperclip/USAGE +2 -2
- data/generators/paperclip/paperclip_generator.rb +8 -8
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +31 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip.rb +113 -69
- data/lib/paperclip/attachment.rb +58 -146
- data/lib/paperclip/callback_compatability.rb +50 -22
- data/lib/paperclip/geometry.rb +7 -7
- data/lib/paperclip/interpolations.rb +21 -21
- data/lib/paperclip/iostream.rb +3 -2
- data/lib/paperclip/matchers.rb +29 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +8 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +13 -5
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +13 -7
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +16 -4
- data/lib/paperclip/processor.rb +2 -2
- data/lib/paperclip/railtie.rb +22 -0
- data/lib/paperclip/storage.rb +29 -25
- data/lib/paperclip/style.rb +90 -0
- data/lib/paperclip/thumbnail.rb +20 -15
- data/lib/paperclip/upfile.rb +5 -2
- data/lib/paperclip/version.rb +3 -0
- data/{tasks/paperclip_tasks.rake → lib/tasks/paperclip.rake} +0 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +5 -3
- data/test/attachment_test.rb +52 -74
- data/test/geometry_test.rb +1 -1
- data/test/helper.rb +62 -22
- data/test/integration_test.rb +8 -8
- data/test/interpolations_test.rb +4 -4
- data/test/iostream_test.rb +9 -2
- data/test/matchers/have_attached_file_matcher_test.rb +9 -6
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +15 -8
- data/test/matchers/validate_attachment_presence_matcher_test.rb +11 -6
- data/test/matchers/validate_attachment_size_matcher_test.rb +18 -17
- data/test/paperclip_test.rb +58 -68
- data/test/storage_test.rb +53 -13
- data/test/style_test.rb +141 -0
- data/test/thumbnail_test.rb +17 -17
- data/test/upfile_test.rb +8 -0
- metadata +69 -42
data/lib/paperclip/thumbnail.rb
CHANGED
@@ -9,9 +9,10 @@ module Paperclip
|
|
9
9
|
# which is a "WxH"-style string. +format+ will be inferred from the +file+
|
10
10
|
# unless specified. Thumbnail creation will raise no errors unless
|
11
11
|
# +whiny+ is true (which it is, by default. If +convert_options+ is
|
12
|
-
# set, the options will be appended to the convert command upon image conversion
|
12
|
+
# set, the options will be appended to the convert command upon image conversion
|
13
13
|
def initialize file, options = {}, attachment = nil
|
14
14
|
super
|
15
|
+
|
15
16
|
geometry = options[:geometry]
|
16
17
|
@file = file
|
17
18
|
@crop = geometry[-1,1] == '#'
|
@@ -22,15 +23,19 @@ module Paperclip
|
|
22
23
|
@whiny = options[:whiny].nil? ? true : options[:whiny]
|
23
24
|
@format = options[:format]
|
24
25
|
|
26
|
+
@source_file_options = @source_file_options.split(/\s+/) if @source_file_options.respond_to?(:split)
|
27
|
+
@convert_options = @convert_options.split(/\s+/) if @convert_options.respond_to?(:split)
|
28
|
+
|
25
29
|
@current_format = File.extname(@file.path)
|
26
30
|
@basename = File.basename(@file.path, @current_format)
|
31
|
+
|
27
32
|
end
|
28
33
|
|
29
34
|
# Returns true if the +target_geometry+ is meant to crop.
|
30
35
|
def crop?
|
31
36
|
@crop
|
32
37
|
end
|
33
|
-
|
38
|
+
|
34
39
|
# Returns true if the image is meant to make use of additional convert options.
|
35
40
|
def convert_options?
|
36
41
|
!@convert_options.nil? && !@convert_options.empty?
|
@@ -43,16 +48,17 @@ module Paperclip
|
|
43
48
|
dst = Tempfile.new([@basename, @format].compact.join("."))
|
44
49
|
dst.binmode
|
45
50
|
|
46
|
-
command = <<-end_command
|
47
|
-
#{ source_file_options }
|
48
|
-
"#{ File.expand_path(src.path) }[0]"
|
49
|
-
#{ transformation_command }
|
50
|
-
"#{ File.expand_path(dst.path) }"
|
51
|
-
end_command
|
52
|
-
|
53
51
|
begin
|
54
|
-
|
55
|
-
|
52
|
+
options = [
|
53
|
+
source_file_options,
|
54
|
+
"#{ File.expand_path(src.path) }[0]",
|
55
|
+
transformation_command,
|
56
|
+
convert_options,
|
57
|
+
"#{ File.expand_path(dst.path) }"
|
58
|
+
].flatten.compact
|
59
|
+
|
60
|
+
success = Paperclip.run("convert", *options)
|
61
|
+
rescue PaperclipCommandLineError => e
|
56
62
|
raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if @whiny
|
57
63
|
end
|
58
64
|
|
@@ -63,10 +69,9 @@ module Paperclip
|
|
63
69
|
# into the thumbnail.
|
64
70
|
def transformation_command
|
65
71
|
scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
|
66
|
-
trans =
|
67
|
-
trans << "
|
68
|
-
trans << "
|
69
|
-
trans << " #{convert_options}" if convert_options?
|
72
|
+
trans = []
|
73
|
+
trans << "-resize" << scale unless scale.nil? || scale.empty?
|
74
|
+
trans << "-crop" << crop << "+repage" if crop
|
70
75
|
trans
|
71
76
|
end
|
72
77
|
end
|
data/lib/paperclip/upfile.rb
CHANGED
@@ -15,7 +15,11 @@ module Paperclip
|
|
15
15
|
when %r"html?" then "text/html"
|
16
16
|
when "js" then "application/js"
|
17
17
|
when "csv", "xml", "css" then "text/#{type}"
|
18
|
-
else
|
18
|
+
else
|
19
|
+
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
|
20
|
+
content_type = (Paperclip.run("file", "--mime-type", self.path).split(':').last.strip rescue "application/x-#{type}")
|
21
|
+
content_type = "application/x-#{type}" if content_type.match(/\(.*?\)/)
|
22
|
+
content_type
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
@@ -46,4 +50,3 @@ end
|
|
46
50
|
class File #:nodoc:
|
47
51
|
include Paperclip::Upfile
|
48
52
|
end
|
49
|
-
|
File without changes
|
data/rails/init.rb
ADDED
data/shoulda_macros/paperclip.rb
CHANGED
@@ -46,7 +46,7 @@ module Paperclip
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Tests to ensure that you have file size validations turned on. You
|
49
|
-
# can pass the same options to this that you can to
|
49
|
+
# can pass the same options to this that you can to
|
50
50
|
# validate_attachment_file_size - :less_than, :greater_than, and :in.
|
51
51
|
# :less_than checks that a file is less than a certain size, :greater_than
|
52
52
|
# checks that a file is more than a certain size, and :in takes a Range or
|
@@ -104,8 +104,10 @@ module Paperclip
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
|
108
|
-
|
107
|
+
if defined?(ActionController::Integration::Session)
|
108
|
+
class ActionController::Integration::Session #:nodoc:
|
109
|
+
include Paperclip::Shoulda
|
110
|
+
end
|
109
111
|
end
|
110
112
|
|
111
113
|
class Factory
|
data/test/attachment_test.rb
CHANGED
@@ -11,19 +11,7 @@ class AttachmentTest < Test::Unit::TestCase
|
|
11
11
|
@model = @attachment.instance
|
12
12
|
@model.id = 1234
|
13
13
|
@model.avatar_file_name = "fake.jpg"
|
14
|
-
assert_equal "#{
|
15
|
-
end
|
16
|
-
|
17
|
-
should "call a proc sent to check_guard" do
|
18
|
-
@dummy = Dummy.new
|
19
|
-
@dummy.expects(:one).returns(:one)
|
20
|
-
assert_equal :one, @dummy.avatar.send(:check_guard, lambda{|x| x.one })
|
21
|
-
end
|
22
|
-
|
23
|
-
should "call a method name sent to check_guard" do
|
24
|
-
@dummy = Dummy.new
|
25
|
-
@dummy.expects(:one).returns(:one)
|
26
|
-
assert_equal :one, @dummy.avatar.send(:check_guard, :one)
|
14
|
+
assert_equal "#{Rails.root}/public/fake_models/1234/fake", @attachment.path
|
27
15
|
end
|
28
16
|
|
29
17
|
context "Attachment default_options" do
|
@@ -53,7 +41,7 @@ class AttachmentTest < Test::Unit::TestCase
|
|
53
41
|
setup do
|
54
42
|
@dummy = Dummy.new
|
55
43
|
end
|
56
|
-
|
44
|
+
|
57
45
|
should "return false when asked exists?" do
|
58
46
|
assert !@dummy.avatar.exists?
|
59
47
|
end
|
@@ -67,7 +55,7 @@ class AttachmentTest < Test::Unit::TestCase
|
|
67
55
|
|
68
56
|
Paperclip::Attachment.default_options.keys.each do |key|
|
69
57
|
should "be the default_options for #{key}" do
|
70
|
-
assert_equal @old_default_options[key],
|
58
|
+
assert_equal @old_default_options[key],
|
71
59
|
@attachment.instance_variable_get("@#{key}"),
|
72
60
|
key
|
73
61
|
end
|
@@ -118,12 +106,11 @@ class AttachmentTest < Test::Unit::TestCase
|
|
118
106
|
@dummy.stubs(:id).returns(@id)
|
119
107
|
@file = StringIO.new(".")
|
120
108
|
@dummy.avatar = @file
|
109
|
+
Rails.stubs(:env).returns(@rails_env)
|
121
110
|
end
|
122
111
|
|
123
112
|
should "return the proper path" do
|
124
|
-
|
125
|
-
assert_equal "#{@rails_env}/#{@id}.png", @dummy.avatar.path
|
126
|
-
}
|
113
|
+
assert_equal "#{@rails_env}/#{@id}.png", @dummy.avatar.path
|
127
114
|
end
|
128
115
|
end
|
129
116
|
|
@@ -133,7 +120,7 @@ class AttachmentTest < Test::Unit::TestCase
|
|
133
120
|
:styles => { :default => ["100x100", :png] },
|
134
121
|
:default_style => :default
|
135
122
|
@file = StringIO.new("...")
|
136
|
-
@file.
|
123
|
+
@file.stubs(:original_filename).returns("file.jpg")
|
137
124
|
end
|
138
125
|
should "return the right extension for the path" do
|
139
126
|
@attachment.assign(@file)
|
@@ -162,11 +149,6 @@ class AttachmentTest < Test::Unit::TestCase
|
|
162
149
|
should "report the correct options when sent #extra_options_for(:large)" do
|
163
150
|
assert_equal "-do_stuff", @dummy.avatar.send(:extra_options_for, :large)
|
164
151
|
end
|
165
|
-
|
166
|
-
before_should "call extra_options_for(:thumb/:large)" do
|
167
|
-
Paperclip::Attachment.any_instance.expects(:extra_options_for).with(:thumb)
|
168
|
-
Paperclip::Attachment.any_instance.expects(:extra_options_for).with(:large)
|
169
|
-
end
|
170
152
|
end
|
171
153
|
|
172
154
|
context "An attachment with :convert_options that is a proc" do
|
@@ -194,17 +176,12 @@ class AttachmentTest < Test::Unit::TestCase
|
|
194
176
|
should "report the correct options when sent #extra_options_for(:large)" do
|
195
177
|
assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large)
|
196
178
|
end
|
197
|
-
|
198
|
-
before_should "call extra_options_for(:thumb/:large)" do
|
199
|
-
Paperclip::Attachment.any_instance.expects(:extra_options_for).with(:thumb)
|
200
|
-
Paperclip::Attachment.any_instance.expects(:extra_options_for).with(:large)
|
201
|
-
end
|
202
179
|
end
|
203
|
-
|
180
|
+
|
204
181
|
context "An attachment with :path that is a proc" do
|
205
182
|
setup do
|
206
183
|
rebuild_model :path => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
|
207
|
-
|
184
|
+
|
208
185
|
@file = File.new(File.join(File.dirname(__FILE__),
|
209
186
|
"fixtures",
|
210
187
|
"5k.png"), 'rb')
|
@@ -213,31 +190,31 @@ class AttachmentTest < Test::Unit::TestCase
|
|
213
190
|
@dummyB = Dummy.new(:other => 'b')
|
214
191
|
@dummyB.avatar = @file
|
215
192
|
end
|
216
|
-
|
193
|
+
|
217
194
|
teardown { @file.close }
|
218
|
-
|
195
|
+
|
219
196
|
should "return correct path" do
|
220
197
|
assert_equal "path/a.png", @dummyA.avatar.path
|
221
198
|
assert_equal "path/b.png", @dummyB.avatar.path
|
222
199
|
end
|
223
200
|
end
|
224
|
-
|
201
|
+
|
225
202
|
context "An attachment with :styles that is a proc" do
|
226
203
|
setup do
|
227
204
|
rebuild_model :styles => lambda{ |attachment| {:thumb => "50x50#", :large => "400x400"} }
|
228
|
-
|
205
|
+
|
229
206
|
@attachment = Dummy.new.avatar
|
230
207
|
end
|
231
|
-
|
208
|
+
|
232
209
|
should "have the correct geometry" do
|
233
210
|
assert_equal "50x50#", @attachment.styles[:thumb][:geometry]
|
234
211
|
end
|
235
212
|
end
|
236
|
-
|
213
|
+
|
237
214
|
context "An attachment with :url that is a proc" do
|
238
215
|
setup do
|
239
216
|
rebuild_model :url => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
|
240
|
-
|
217
|
+
|
241
218
|
@file = File.new(File.join(File.dirname(__FILE__),
|
242
219
|
"fixtures",
|
243
220
|
"5k.png"), 'rb')
|
@@ -246,16 +223,16 @@ class AttachmentTest < Test::Unit::TestCase
|
|
246
223
|
@dummyB = Dummy.new(:other => 'b')
|
247
224
|
@dummyB.avatar = @file
|
248
225
|
end
|
249
|
-
|
226
|
+
|
250
227
|
teardown { @file.close }
|
251
|
-
|
228
|
+
|
252
229
|
should "return correct url" do
|
253
230
|
assert_equal "path/a.png", @dummyA.avatar.url(:original, false)
|
254
231
|
assert_equal "path/b.png", @dummyB.avatar.url(:original, false)
|
255
232
|
end
|
256
233
|
end
|
257
234
|
|
258
|
-
geometry_specs = [
|
235
|
+
geometry_specs = [
|
259
236
|
[ lambda{|z| "50x50#" }, :png ],
|
260
237
|
lambda{|z| "50x50#" },
|
261
238
|
{ :geometry => lambda{|z| "50x50#" } }
|
@@ -267,10 +244,6 @@ class AttachmentTest < Test::Unit::TestCase
|
|
267
244
|
@attachment = Dummy.new.avatar
|
268
245
|
end
|
269
246
|
|
270
|
-
should "not run the procs immediately" do
|
271
|
-
assert_kind_of Proc, @attachment.styles[:normal][:geometry]
|
272
|
-
end
|
273
|
-
|
274
247
|
context "when assigned" do
|
275
248
|
setup do
|
276
249
|
@file = StringIO.new(".")
|
@@ -307,10 +280,6 @@ class AttachmentTest < Test::Unit::TestCase
|
|
307
280
|
@attachment = Dummy.new.avatar
|
308
281
|
end
|
309
282
|
|
310
|
-
should "not run the proc immediately" do
|
311
|
-
assert_kind_of Proc, @attachment.styles[:normal][:processors]
|
312
|
-
end
|
313
|
-
|
314
283
|
context "when assigned" do
|
315
284
|
setup do
|
316
285
|
@attachment.assign(StringIO.new("."))
|
@@ -354,19 +323,22 @@ class AttachmentTest < Test::Unit::TestCase
|
|
354
323
|
setup { @dummy.avatar = @file }
|
355
324
|
|
356
325
|
before_should "call #make on all specified processors" do
|
326
|
+
Paperclip::Thumbnail.expects(:make).with(any_parameters).returns(@file)
|
327
|
+
Paperclip::Test.expects(:make).with(any_parameters).returns(@file)
|
328
|
+
end
|
329
|
+
|
330
|
+
before_should "call #make with the right parameters passed as second argument" do
|
357
331
|
expected_params = @style_params[:once].merge({:processors => [:thumbnail, :test], :whiny => true, :convert_options => ""})
|
358
|
-
Paperclip::Thumbnail.expects(:make).with(
|
359
|
-
Paperclip::Test.expects(:make).with(@file, expected_params, @dummy.avatar).returns(@file)
|
332
|
+
Paperclip::Thumbnail.expects(:make).with(anything, expected_params, anything).returns(@file)
|
360
333
|
end
|
361
|
-
|
334
|
+
|
362
335
|
before_should "call #make with attachment passed as third argument" do
|
363
|
-
|
364
|
-
Paperclip::Test.expects(:make).with(@file, expected_params, @dummy.avatar).returns(@file)
|
336
|
+
Paperclip::Test.expects(:make).with(anything, anything, @dummy.avatar).returns(@file)
|
365
337
|
end
|
366
338
|
end
|
367
339
|
end
|
368
340
|
|
369
|
-
context "An attachment with no processors defined" do
|
341
|
+
context "An attachment with styles but no processors defined" do
|
370
342
|
setup do
|
371
343
|
rebuild_model :processors => [], :styles => {:something => 1}
|
372
344
|
@dummy = Dummy.new
|
@@ -377,9 +349,20 @@ class AttachmentTest < Test::Unit::TestCase
|
|
377
349
|
end
|
378
350
|
end
|
379
351
|
|
352
|
+
context "An attachment without styles and with no processors defined" do
|
353
|
+
setup do
|
354
|
+
rebuild_model :processors => [], :styles => {}
|
355
|
+
@dummy = Dummy.new
|
356
|
+
@file = StringIO.new("...")
|
357
|
+
end
|
358
|
+
should "not raise when assigned to" do
|
359
|
+
@dummy.avatar = @file
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
380
363
|
context "Assigning an attachment with post_process hooks" do
|
381
364
|
setup do
|
382
|
-
|
365
|
+
rebuild_class :styles => { :something => "100x100#" }
|
383
366
|
Dummy.class_eval do
|
384
367
|
before_avatar_post_process :do_before_avatar
|
385
368
|
after_avatar_post_process :do_after_avatar
|
@@ -419,16 +402,16 @@ class AttachmentTest < Test::Unit::TestCase
|
|
419
402
|
@dummy.expects(:do_before_avatar).never
|
420
403
|
@dummy.expects(:do_after_avatar).never
|
421
404
|
@dummy.expects(:do_before_all).with().returns(false)
|
422
|
-
@dummy.expects(:do_after_all)
|
405
|
+
@dummy.expects(:do_after_all)
|
423
406
|
Paperclip::Thumbnail.expects(:make).never
|
424
407
|
@dummy.avatar = @file
|
425
408
|
end
|
426
409
|
|
427
410
|
should "cancel the processing if a before_avatar_post_process returns false" do
|
428
411
|
@dummy.expects(:do_before_avatar).with().returns(false)
|
429
|
-
@dummy.expects(:do_after_avatar)
|
412
|
+
@dummy.expects(:do_after_avatar)
|
430
413
|
@dummy.expects(:do_before_all).with().returns(true)
|
431
|
-
@dummy.expects(:do_after_all)
|
414
|
+
@dummy.expects(:do_after_all)
|
432
415
|
Paperclip::Thumbnail.expects(:make).never
|
433
416
|
@dummy.avatar = @file
|
434
417
|
end
|
@@ -438,15 +421,11 @@ class AttachmentTest < Test::Unit::TestCase
|
|
438
421
|
setup do
|
439
422
|
rebuild_model :styles => { :something => "100x100#" }
|
440
423
|
@file = StringIO.new(".")
|
441
|
-
@file.
|
442
|
-
@file.
|
424
|
+
@file.stubs(:original_filename).returns("5k.png\n\n")
|
425
|
+
@file.stubs(:content_type).returns("image/png\n\n")
|
443
426
|
@file.stubs(:to_tempfile).returns(@file)
|
444
427
|
@dummy = Dummy.new
|
445
428
|
Paperclip::Thumbnail.expects(:make).returns(@file)
|
446
|
-
@dummy.expects(:run_callbacks).with(:before_avatar_post_process, {:original => @file})
|
447
|
-
@dummy.expects(:run_callbacks).with(:before_post_process, {:original => @file})
|
448
|
-
@dummy.expects(:run_callbacks).with(:after_avatar_post_process, {:original => @file, :something => @file})
|
449
|
-
@dummy.expects(:run_callbacks).with(:after_post_process, {:original => @file, :something => @file})
|
450
429
|
@attachment = @dummy.avatar
|
451
430
|
@dummy.avatar = @file
|
452
431
|
end
|
@@ -463,7 +442,7 @@ class AttachmentTest < Test::Unit::TestCase
|
|
463
442
|
context "Attachment with strange letters" do
|
464
443
|
setup do
|
465
444
|
rebuild_model
|
466
|
-
|
445
|
+
|
467
446
|
@not_file = mock
|
468
447
|
@tempfile = mock
|
469
448
|
@not_file.stubs(:nil?).returns(false)
|
@@ -472,21 +451,18 @@ class AttachmentTest < Test::Unit::TestCase
|
|
472
451
|
@not_file.expects(:to_tempfile).returns(@tempfile)
|
473
452
|
@not_file.expects(:original_filename).returns("sheep_say_bæ.png\r\n")
|
474
453
|
@not_file.expects(:content_type).returns("image/png\r\n")
|
475
|
-
|
454
|
+
|
476
455
|
@dummy = Dummy.new
|
477
456
|
@attachment = @dummy.avatar
|
478
457
|
@attachment.expects(:valid_assignment?).with(@not_file).returns(true)
|
479
458
|
@attachment.expects(:queue_existing_for_delete)
|
480
459
|
@attachment.expects(:post_process)
|
481
|
-
@attachment.expects(:valid?).returns(true)
|
482
|
-
@attachment.expects(:validate)
|
483
460
|
@dummy.avatar = @not_file
|
484
461
|
end
|
485
|
-
|
486
|
-
should "remove strange letters
|
487
|
-
assert_equal "
|
462
|
+
|
463
|
+
should "not remove strange letters" do
|
464
|
+
assert_equal "sheep_say_bæ.png", @dummy.avatar.original_filename
|
488
465
|
end
|
489
|
-
|
490
466
|
end
|
491
467
|
|
492
468
|
context "An attachment" do
|
@@ -498,6 +474,7 @@ class AttachmentTest < Test::Unit::TestCase
|
|
498
474
|
FileUtils.rm_rf("tmp")
|
499
475
|
rebuild_model
|
500
476
|
@instance = Dummy.new
|
477
|
+
@instance.stubs(:id).returns 123
|
501
478
|
@attachment = Paperclip::Attachment.new(:avatar, @instance)
|
502
479
|
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
|
503
480
|
end
|
@@ -606,6 +583,7 @@ class AttachmentTest < Test::Unit::TestCase
|
|
606
583
|
should "commit the files to disk" do
|
607
584
|
[:large, :medium, :small].each do |style|
|
608
585
|
io = @attachment.to_file(style)
|
586
|
+
# p "in commit to disk test, io is #{io.inspect} and @instance.id is #{@instance.id}"
|
609
587
|
assert File.exists?(io)
|
610
588
|
assert ! io.is_a?(::Tempfile)
|
611
589
|
io.close
|
@@ -619,7 +597,7 @@ class AttachmentTest < Test::Unit::TestCase
|
|
619
597
|
cmd = %Q[identify -format "%w %h %b %m" "#{@attachment.path(style.first)}"]
|
620
598
|
out = `#{cmd}`
|
621
599
|
width, height, size, format = out.split(" ")
|
622
|
-
assert_equal style[1].to_s, width.to_s
|
600
|
+
assert_equal style[1].to_s, width.to_s
|
623
601
|
assert_equal style[2].to_s, height.to_s
|
624
602
|
assert_equal style[3].to_s, format.to_s
|
625
603
|
end
|
data/test/geometry_test.rb
CHANGED
@@ -65,7 +65,7 @@ class GeometryTest < Test::Unit::TestCase
|
|
65
65
|
assert_equal "123x456#{mod}", @geo.to_s
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
|
70
70
|
should "ensure the modifier #{mod.inspect} is preserved with no height" do
|
71
71
|
assert @geo = Paperclip::Geometry.parse("123x#{mod}")
|
data/test/helper.rb
CHANGED
@@ -1,24 +1,54 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'shoulda'
|
4
2
|
require 'tempfile'
|
3
|
+
require 'test/unit'
|
5
4
|
|
6
|
-
|
5
|
+
require 'shoulda'
|
7
6
|
require 'mocha'
|
8
7
|
|
9
|
-
|
8
|
+
case ENV['RAILS_VERSION']
|
9
|
+
when '2.1' then
|
10
|
+
gem 'activerecord', '~>2.1.0'
|
11
|
+
gem 'activesupport', '~>2.1.0'
|
12
|
+
gem 'actionpack', '~>2.1.0'
|
13
|
+
when '3.0' then
|
14
|
+
gem 'activerecord', '~>3.0.0'
|
15
|
+
gem 'activesupport', '~>3.0.0'
|
16
|
+
gem 'actionpack', '~>3.0.0'
|
17
|
+
else
|
18
|
+
gem 'activerecord', '~>2.3.0'
|
19
|
+
gem 'activesupport', '~>2.3.0'
|
20
|
+
gem 'actionpack', '~>2.3.0'
|
21
|
+
end
|
10
22
|
|
11
23
|
require 'active_record'
|
24
|
+
require 'active_record/version'
|
12
25
|
require 'active_support'
|
26
|
+
require 'action_pack'
|
27
|
+
|
28
|
+
puts "Testing against version #{ActiveRecord::VERSION::STRING}"
|
29
|
+
|
13
30
|
begin
|
14
31
|
require 'ruby-debug'
|
15
|
-
rescue LoadError
|
16
|
-
puts "
|
32
|
+
rescue LoadError => e
|
33
|
+
puts "debugger disabled"
|
17
34
|
end
|
18
35
|
|
19
|
-
ROOT
|
20
|
-
|
21
|
-
|
36
|
+
ROOT = File.join(File.dirname(__FILE__), '..')
|
37
|
+
|
38
|
+
def silence_warnings
|
39
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
40
|
+
yield
|
41
|
+
ensure
|
42
|
+
$VERBOSE = old_verbose
|
43
|
+
end
|
44
|
+
|
45
|
+
class Test::Unit::TestCase
|
46
|
+
def setup
|
47
|
+
silence_warnings do
|
48
|
+
Object.const_set(:Rails, stub('Rails', :root => ROOT, :env => 'test'))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
22
52
|
|
23
53
|
$LOAD_PATH << File.join(ROOT, 'lib')
|
24
54
|
$LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
|
@@ -27,7 +57,7 @@ require File.join(ROOT, 'lib', 'paperclip.rb')
|
|
27
57
|
|
28
58
|
require 'shoulda_macros/paperclip'
|
29
59
|
|
30
|
-
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
60
|
+
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
31
61
|
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
32
62
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
33
63
|
ActiveRecord::Base.establish_connection(config['test'])
|
@@ -70,17 +100,6 @@ def rebuild_class options = {}
|
|
70
100
|
end
|
71
101
|
end
|
72
102
|
|
73
|
-
def temporary_rails_env(new_env)
|
74
|
-
old_env = Object.const_defined?("RAILS_ENV") ? RAILS_ENV : nil
|
75
|
-
silence_warnings do
|
76
|
-
Object.const_set("RAILS_ENV", new_env)
|
77
|
-
end
|
78
|
-
yield
|
79
|
-
silence_warnings do
|
80
|
-
Object.const_set("RAILS_ENV", old_env)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
103
|
class FakeModel
|
85
104
|
attr_accessor :avatar_file_name,
|
86
105
|
:avatar_file_size,
|
@@ -92,8 +111,9 @@ class FakeModel
|
|
92
111
|
@errors ||= []
|
93
112
|
end
|
94
113
|
|
95
|
-
def
|
114
|
+
def run_paperclip_callbacks name, *args
|
96
115
|
end
|
116
|
+
|
97
117
|
end
|
98
118
|
|
99
119
|
def attachment options
|
@@ -106,3 +126,23 @@ def silence_warnings
|
|
106
126
|
ensure
|
107
127
|
$VERBOSE = old_verbose
|
108
128
|
end
|
129
|
+
|
130
|
+
def should_accept_dummy_class
|
131
|
+
should "accept the class" do
|
132
|
+
assert_accepts @matcher, @dummy_class
|
133
|
+
end
|
134
|
+
|
135
|
+
should "accept an instance of that class" do
|
136
|
+
assert_accepts @matcher, @dummy_class.new
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def should_reject_dummy_class
|
141
|
+
should "reject the class" do
|
142
|
+
assert_rejects @matcher, @dummy_class
|
143
|
+
end
|
144
|
+
|
145
|
+
should "reject an instance of that class" do
|
146
|
+
assert_rejects @matcher, @dummy_class.new
|
147
|
+
end
|
148
|
+
end
|