cloudfuji_paperclip 2.4.6 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +9 -6
  3. data/Appraisals +6 -6
  4. data/CONTRIBUTING.md +34 -2
  5. data/Gemfile +2 -0
  6. data/NEWS +90 -0
  7. data/README.md +62 -29
  8. data/RUNNING_TESTS.md +4 -0
  9. data/Rakefile +7 -2
  10. data/UPGRADING +14 -0
  11. data/features/basic_integration.feature +11 -7
  12. data/features/rake_tasks.feature +1 -1
  13. data/features/step_definitions/attachment_steps.rb +11 -2
  14. data/features/step_definitions/rails_steps.rb +17 -79
  15. data/features/support/env.rb +3 -0
  16. data/features/support/fakeweb.rb +7 -0
  17. data/features/support/file_helpers.rb +24 -0
  18. data/features/support/rails.rb +3 -3
  19. data/gemfiles/{rails3_1.gemfile → 3.0.gemfile} +3 -1
  20. data/gemfiles/{rails2.gemfile → 3.1.gemfile} +3 -1
  21. data/gemfiles/{rails3.gemfile → 3.2.gemfile} +3 -1
  22. data/images.rake +21 -0
  23. data/lib/cloudfuji_paperclip.rb +1 -0
  24. data/lib/generators/paperclip/paperclip_generator.rb +1 -2
  25. data/lib/paperclip.rb +54 -319
  26. data/lib/paperclip/attachment.rb +86 -107
  27. data/lib/paperclip/attachment_options.rb +9 -0
  28. data/lib/paperclip/callbacks.rb +30 -0
  29. data/lib/paperclip/errors.rb +27 -0
  30. data/lib/paperclip/geometry.rb +6 -4
  31. data/lib/paperclip/glue.rb +23 -0
  32. data/lib/paperclip/helpers.rb +71 -0
  33. data/lib/paperclip/instance_methods.rb +35 -0
  34. data/lib/paperclip/interpolations.rb +4 -4
  35. data/lib/paperclip/io_adapters/attachment_adapter.rb +69 -0
  36. data/lib/paperclip/io_adapters/file_adapter.rb +81 -0
  37. data/lib/paperclip/io_adapters/identity_adapter.rb +12 -0
  38. data/lib/paperclip/io_adapters/nil_adapter.rb +34 -0
  39. data/lib/paperclip/io_adapters/registry.rb +32 -0
  40. data/lib/paperclip/io_adapters/stringio_adapter.rb +64 -0
  41. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +63 -0
  42. data/lib/paperclip/locales/en.yml +17 -0
  43. data/lib/paperclip/logger.rb +21 -0
  44. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +5 -5
  45. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +7 -7
  46. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -11
  47. data/lib/paperclip/missing_attachment_styles.rb +6 -9
  48. data/lib/paperclip/processor.rb +32 -17
  49. data/lib/paperclip/railtie.rb +13 -17
  50. data/lib/paperclip/storage/filesystem.rb +4 -13
  51. data/lib/paperclip/storage/fog.rb +33 -24
  52. data/lib/paperclip/storage/s3.rb +36 -28
  53. data/lib/paperclip/tempfile.rb +41 -0
  54. data/lib/paperclip/thumbnail.rb +2 -3
  55. data/lib/paperclip/validators.rb +45 -0
  56. data/lib/paperclip/validators/attachment_content_type_validator.rb +54 -0
  57. data/lib/paperclip/validators/attachment_presence_validator.rb +26 -0
  58. data/lib/paperclip/validators/attachment_size_validator.rb +102 -0
  59. data/lib/paperclip/version.rb +1 -1
  60. data/lib/tasks/paperclip.rake +4 -12
  61. data/paperclip.gemspec +15 -5
  62. data/test/adapter_registry_test.rb +32 -0
  63. data/test/attachment_adapter_test.rb +51 -0
  64. data/test/attachment_options_test.rb +27 -0
  65. data/test/attachment_test.rb +130 -46
  66. data/test/file_adapter_test.rb +88 -0
  67. data/test/generator_test.rb +78 -0
  68. data/test/geometry_test.rb +5 -5
  69. data/test/helper.rb +21 -22
  70. data/test/identity_adapter_test.rb +8 -0
  71. data/test/integration_test.rb +55 -102
  72. data/test/interpolations_test.rb +15 -5
  73. data/test/matchers/validate_attachment_content_type_matcher_test.rb +23 -0
  74. data/test/matchers/validate_attachment_presence_matcher_test.rb +21 -0
  75. data/test/matchers/validate_attachment_size_matcher_test.rb +37 -2
  76. data/test/nil_adapter_test.rb +25 -0
  77. data/test/paperclip_missing_attachment_styles_test.rb +16 -0
  78. data/test/paperclip_test.rb +34 -183
  79. data/test/storage/filesystem_test.rb +27 -27
  80. data/test/storage/fog_test.rb +68 -12
  81. data/test/storage/s3_live_test.rb +79 -38
  82. data/test/storage/s3_test.rb +204 -34
  83. data/test/stringio_adapter_test.rb +42 -0
  84. data/test/thumbnail_test.rb +29 -8
  85. data/test/uploaded_file_adapter_test.rb +98 -0
  86. data/test/url_generator_test.rb +8 -8
  87. data/test/validators/attachment_content_type_validator_test.rb +192 -0
  88. data/test/validators/attachment_presence_validator_test.rb +85 -0
  89. data/test/validators/attachment_size_validator_test.rb +207 -0
  90. data/test/validators_test.rb +25 -0
  91. metadata +166 -59
  92. data/generators/paperclip/USAGE +0 -5
  93. data/generators/paperclip/paperclip_generator.rb +0 -27
  94. data/generators/paperclip/templates/paperclip_migration.rb.erb +0 -19
  95. data/init.rb +0 -4
  96. data/lib/paperclip/callback_compatibility.rb +0 -61
  97. data/lib/paperclip/iostream.rb +0 -45
  98. data/lib/paperclip/upfile.rb +0 -62
  99. data/rails/init.rb +0 -2
  100. data/test/.gitignore +0 -1
  101. data/test/fixtures/question?mark.png +0 -0
  102. data/test/iostream_test.rb +0 -71
  103. data/test/upfile_test.rb +0 -53
@@ -0,0 +1,78 @@
1
+ require './test/helper'
2
+ require 'rails/generators'
3
+ require 'generators/paperclip/paperclip_generator'
4
+
5
+ class GeneratorTest < Rails::Generators::TestCase
6
+ tests PaperclipGenerator
7
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
8
+ setup :prepare_destination
9
+
10
+ context 'running migration' do
11
+ context 'with single attachment name' do
12
+ setup do
13
+ run_generator %w(user avatar)
14
+ end
15
+
16
+ should 'create a correct migration file' do
17
+ assert_migration 'db/migrate/add_attachment_avatar_to_users.rb' do |migration|
18
+ assert_match /class AddAttachmentAvatarToUsers/, migration
19
+
20
+ assert_class_method :up, migration do |up|
21
+ assert_match /add_column :users, :avatar_file_name, :string/, up
22
+ assert_match /add_column :users, :avatar_content_type, :string/, up
23
+ assert_match /add_column :users, :avatar_file_size, :integer/, up
24
+ assert_match /add_column :users, :avatar_updated_at, :datetime/, up
25
+ end
26
+
27
+ assert_class_method :down, migration do |down|
28
+ assert_match /remove_column :users, :avatar_file_name/, down
29
+ assert_match /remove_column :users, :avatar_content_type/, down
30
+ assert_match /remove_column :users, :avatar_file_size/, down
31
+ assert_match /remove_column :users, :avatar_updated_at/, down
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ context 'with multiple attachment names' do
38
+ setup do
39
+ run_generator %w(user avatar photo)
40
+ end
41
+
42
+ should 'create a correct migration file' do
43
+ assert_migration 'db/migrate/add_attachment_avatar_photo_to_users.rb' do |migration|
44
+ assert_match /class AddAttachmentAvatarPhotoToUsers/, migration
45
+
46
+ assert_class_method :up, migration do |up|
47
+ assert_match /add_column :users, :avatar_file_name, :string/, up
48
+ assert_match /add_column :users, :avatar_content_type, :string/, up
49
+ assert_match /add_column :users, :avatar_file_size, :integer/, up
50
+ assert_match /add_column :users, :avatar_updated_at, :datetime/, up
51
+ assert_match /add_column :users, :photo_file_name, :string/, up
52
+ assert_match /add_column :users, :photo_content_type, :string/, up
53
+ assert_match /add_column :users, :photo_file_size, :integer/, up
54
+ assert_match /add_column :users, :photo_updated_at, :datetime/, up
55
+ end
56
+
57
+ assert_class_method :down, migration do |down|
58
+ assert_match /remove_column :users, :avatar_file_name/, down
59
+ assert_match /remove_column :users, :avatar_content_type/, down
60
+ assert_match /remove_column :users, :avatar_file_size/, down
61
+ assert_match /remove_column :users, :avatar_updated_at/, down
62
+ assert_match /remove_column :users, :photo_file_name/, down
63
+ assert_match /remove_column :users, :photo_content_type/, down
64
+ assert_match /remove_column :users, :photo_file_size/, down
65
+ assert_match /remove_column :users, :photo_updated_at/, down
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ context 'without required arguments' do
72
+ should 'not create the migration' do
73
+ silence_stream(STDERR) { run_generator %w() }
74
+ assert_no_migration 'db/migrate/add_attachment_avatar_to_users.rb'
75
+ end
76
+ end
77
+ end
78
+ end
@@ -117,30 +117,30 @@ class GeometryTest < Test::Unit::TestCase
117
117
 
118
118
  should "not generate from a bad file" do
119
119
  file = "/home/This File Does Not Exist.omg"
120
- assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
120
+ assert_raise(Paperclip::Errors::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
121
121
  end
122
122
 
123
123
  should "not generate from a blank filename" do
124
124
  file = ""
125
- assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
125
+ assert_raise(Paperclip::Errors::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
126
126
  end
127
127
 
128
128
  should "not generate from a nil file" do
129
129
  file = nil
130
- assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
130
+ assert_raise(Paperclip::Errors::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
131
131
  end
132
132
 
133
133
  should "not generate from a file with no path" do
134
134
  file = mock("file", :path => "")
135
135
  file.stubs(:respond_to?).with(:path).returns(true)
136
- assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
136
+ assert_raise(Paperclip::Errors::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
137
137
  end
138
138
 
139
139
  should "let us know when a command isn't found versus a processing error" do
140
140
  old_path = ENV['PATH']
141
141
  begin
142
142
  ENV['PATH'] = ''
143
- assert_raises(Paperclip::CommandNotFoundError) do
143
+ assert_raises(Paperclip::Errors::CommandNotFoundError) do
144
144
  file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
145
145
  @geo = Paperclip::Geometry.from_file(file)
146
146
  end
@@ -5,14 +5,15 @@ require 'test/unit'
5
5
 
6
6
  require 'shoulda'
7
7
  require 'mocha'
8
+ require 'bourne'
8
9
 
9
10
  require 'active_record'
10
11
  require 'active_record/version'
11
12
  require 'active_support'
13
+ require 'active_support/core_ext'
12
14
  require 'mime/types'
13
15
  require 'pathname'
14
-
15
- require 'pathname'
16
+ require 'ostruct'
16
17
 
17
18
  puts "Testing against version #{ActiveRecord::VERSION::STRING}"
18
19
 
@@ -26,13 +27,6 @@ end
26
27
 
27
28
  ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
28
29
 
29
- def silence_warnings
30
- old_verbose, $VERBOSE = $VERBOSE, nil
31
- yield
32
- ensure
33
- $VERBOSE = old_verbose
34
- end
35
-
36
30
  class Test::Unit::TestCase
37
31
  def setup
38
32
  silence_warnings do
@@ -54,15 +48,26 @@ ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FIL
54
48
  ActiveRecord::Base.establish_connection(config['test'])
55
49
  Paperclip.options[:logger] = ActiveRecord::Base.logger
56
50
 
57
- Dir[File.join(File.dirname(__FILE__), 'support','*')].each do |f|
58
- require f
51
+ def require_everything_in_directory(directory_name)
52
+ Dir[File.join(File.dirname(__FILE__), directory_name, '*')].each do |f|
53
+ require f
54
+ end
59
55
  end
60
56
 
57
+ require_everything_in_directory('support')
58
+
61
59
  def reset_class class_name
62
60
  ActiveRecord::Base.send(:include, Paperclip::Glue)
63
61
  Object.send(:remove_const, class_name) rescue nil
64
62
  klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
65
- klass.class_eval{ include Paperclip::Glue }
63
+
64
+ klass.class_eval do
65
+ include Paperclip::Glue
66
+ end
67
+
68
+ klass.reset_column_information
69
+ klass.connection_pool.clear_table_cache!(klass.table_name) if klass.connection_pool.respond_to?(:clear_table_cache!)
70
+ klass.connection.schema_cache.clear_table_cache!(klass.table_name) if klass.connection.respond_to?(:schema_cache)
66
71
  klass
67
72
  end
68
73
 
@@ -89,15 +94,10 @@ def rebuild_model options = {}
89
94
  end
90
95
 
91
96
  def rebuild_class options = {}
92
- ActiveRecord::Base.send(:include, Paperclip::Glue)
93
- Object.send(:remove_const, "Dummy") rescue nil
94
- Object.const_set("Dummy", Class.new(ActiveRecord::Base))
95
- Paperclip.reset_duplicate_clash_check!
96
- Dummy.class_eval do
97
- include Paperclip::Glue
98
- has_attached_file :avatar, options
97
+ reset_class("Dummy").tap do |klass|
98
+ klass.has_attached_file :avatar, options
99
+ Paperclip.reset_duplicate_clash_check!
99
100
  end
100
- Dummy.reset_column_information
101
101
  end
102
102
 
103
103
  class FakeModel
@@ -114,10 +114,9 @@ class FakeModel
114
114
 
115
115
  def run_paperclip_callbacks name, *args
116
116
  end
117
-
118
117
  end
119
118
 
120
- def attachment options
119
+ def attachment(options={})
121
120
  Paperclip::Attachment.new(:avatar, FakeModel.new, options)
122
121
  end
123
122
 
@@ -0,0 +1,8 @@
1
+ require './test/helper'
2
+
3
+ class IdentityAdapterTest < Test::Unit::TestCase
4
+ should "respond to #new by returning the argument" do
5
+ adapter = Paperclip::IdentityAdapter.new
6
+ assert_equal :target, adapter.new(:target)
7
+ end
8
+ end
@@ -10,6 +10,8 @@ class IntegrationTest < Test::Unit::TestCase
10
10
  end
11
11
  end
12
12
 
13
+ teardown { @file.close }
14
+
13
15
  should "not exceed the open file limit" do
14
16
  assert_nothing_raised do
15
17
  dummies = Dummy.find(:all)
@@ -40,12 +42,16 @@ class IntegrationTest < Test::Unit::TestCase
40
42
 
41
43
  should "not raise an error" do
42
44
  assert_nothing_raised do
43
- @dummy.avatar.reprocess!
45
+ silence_stream(STDERR) do
46
+ @dummy.avatar.reprocess!
47
+ end
44
48
  end
45
49
  end
46
50
 
47
51
  should "return false" do
48
- assert ! @dummy.avatar.reprocess!
52
+ silence_stream(STDERR) do
53
+ assert !@dummy.avatar.reprocess!
54
+ end
49
55
  end
50
56
 
51
57
  teardown { File.chmod(0644, @dummy.avatar.path) }
@@ -54,7 +60,6 @@ class IntegrationTest < Test::Unit::TestCase
54
60
  context "redefining its attachment styles" do
55
61
  setup do
56
62
  Dummy.class_eval do
57
- has_attached_file :avatar, :styles => { :thumb => "150x25#" }
58
63
  has_attached_file :avatar, :styles => { :thumb => "150x25#", :dynamic => lambda { |a| '50x50#' } }
59
64
  end
60
65
  @d2 = Dummy.find(@dummy.id)
@@ -71,28 +76,12 @@ class IntegrationTest < Test::Unit::TestCase
71
76
  should "change the timestamp" do
72
77
  assert_not_equal @original_timestamp, @d2.avatar_updated_at
73
78
  end
74
-
75
- should "clean up the old original if it is a tempfile" do
76
- original = @d2.avatar.to_file(:original)
77
- tf = Paperclip::Tempfile.new('original')
78
- tf.binmode
79
- original.binmode
80
- tf.write(original.read)
81
- original.close
82
- tf.rewind
83
-
84
- File.expects(:unlink).with(tf.instance_variable_get(:@tmpname))
85
-
86
- @d2.avatar.expects(:to_file).with(:original).returns(tf)
87
-
88
- @d2.avatar.reprocess!
89
- end
90
79
  end
91
80
  end
92
81
 
93
82
  context "Attachment" do
94
83
  setup do
95
- @thumb_path = "./test/../public/system/avatars/1/thumb/5k.png"
84
+ @thumb_path = "./test/../public/system/dummies/avatars/000/000/001/thumb/5k.png"
96
85
  File.delete(@thumb_path) if File.exists?(@thumb_path)
97
86
  rebuild_model :styles => { :thumb => "50x50#" }
98
87
  @dummy = Dummy.new
@@ -121,8 +110,8 @@ class IntegrationTest < Test::Unit::TestCase
121
110
 
122
111
  context "Attachment with no generated thumbnails" do
123
112
  setup do
124
- @thumb_small_path = "./test/../public/system/avatars/1/thumb_small/5k.png"
125
- @thumb_large_path = "./test/../public/system/avatars/1/thumb_large/5k.png"
113
+ @thumb_small_path = "./test/../public/system/dummies/avatars/000/000/001/thumb_small/5k.png"
114
+ @thumb_large_path = "./test/../public/system/dummies/avatars/000/000/001/thumb_large/5k.png"
126
115
  File.delete(@thumb_small_path) if File.exists?(@thumb_small_path)
127
116
  File.delete(@thumb_large_path) if File.exists?(@thumb_large_path)
128
117
  rebuild_model :styles => { :thumb_small => "50x50#", :thumb_large => "60x60#" }
@@ -173,7 +162,7 @@ class IntegrationTest < Test::Unit::TestCase
173
162
  end
174
163
 
175
164
  should "report the file size of the processed file and not the original" do
176
- assert_not_equal @file.size, @dummy.avatar.size
165
+ assert_not_equal File.size(@file.path), @dummy.avatar.size
177
166
  end
178
167
 
179
168
  teardown { @file.close }
@@ -225,48 +214,6 @@ class IntegrationTest < Test::Unit::TestCase
225
214
  end
226
215
  end
227
216
 
228
- context "A model with no attachment validation" do
229
- setup do
230
- rebuild_model :styles => { :large => "300x300>",
231
- :medium => "100x100",
232
- :thumb => ["32x32#", :gif] },
233
- :default_style => :medium,
234
- :url => "/:attachment/:class/:style/:id/:basename.:extension",
235
- :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
236
- @dummy = Dummy.new
237
- end
238
-
239
- should "have its definition return false when asked about whiny_thumbnails" do
240
- assert ! Dummy.attachment_definitions[:avatar][:whiny_thumbnails]
241
- end
242
-
243
- context "when validates_attachment_thumbnails is called" do
244
- setup do
245
- Dummy.validates_attachment_thumbnails :avatar
246
- end
247
-
248
- should "have its definition return true when asked about whiny_thumbnails" do
249
- assert_equal true, Dummy.attachment_definitions[:avatar][:whiny_thumbnails]
250
- end
251
- end
252
-
253
- context "redefined to have attachment validations" do
254
- setup do
255
- rebuild_model :styles => { :large => "300x300>",
256
- :medium => "100x100",
257
- :thumb => ["32x32#", :gif] },
258
- :whiny_thumbnails => true,
259
- :default_style => :medium,
260
- :url => "/:attachment/:class/:style/:id/:basename.:extension",
261
- :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
262
- end
263
-
264
- should "have its definition return true when asked about whiny_thumbnails" do
265
- assert_equal true, Dummy.attachment_definitions[:avatar][:whiny_thumbnails]
266
- end
267
- end
268
- end
269
-
270
217
  context "A model with no convert_options setting" do
271
218
  setup do
272
219
  rebuild_model :styles => { :large => "300x300>",
@@ -331,12 +278,33 @@ class IntegrationTest < Test::Unit::TestCase
331
278
  end
332
279
  end
333
280
 
281
+ [000,002,022].each do |umask|
282
+ context "when the umask is #{umask}" do
283
+ setup do
284
+ rebuild_model
285
+ @dummy = Dummy.new
286
+ @file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
287
+ @umask = File.umask(umask)
288
+ end
289
+
290
+ teardown do
291
+ File.umask @umask
292
+ @file.close
293
+ end
294
+
295
+ should "respect the current umask" do
296
+ @dummy.avatar = @file
297
+ @dummy.save
298
+ assert_equal 0666&~umask, 0666&File.stat(@dummy.avatar.path).mode
299
+ end
300
+ end
301
+ end
302
+
334
303
  context "A model with a filesystem attachment" do
335
304
  setup do
336
305
  rebuild_model :styles => { :large => "300x300>",
337
306
  :medium => "100x100",
338
307
  :thumb => ["32x32#", :gif] },
339
- :whiny_thumbnails => true,
340
308
  :default_style => :medium,
341
309
  :url => "/:attachment/:class/:style/:id/:basename.:extension",
342
310
  :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@@ -349,6 +317,8 @@ class IntegrationTest < Test::Unit::TestCase
349
317
  assert @dummy.save
350
318
  end
351
319
 
320
+ teardown { [@file, @bad_file].each(&:close) }
321
+
352
322
  should "write and delete its files" do
353
323
  [["434x66", :original],
354
324
  ["300x46", :large],
@@ -367,8 +337,6 @@ class IntegrationTest < Test::Unit::TestCase
367
337
  assert_equal "100x15", `identify -format "%wx%h" "#{@d2.avatar.path(:medium)}"`.chomp
368
338
  assert_equal "32x32", `identify -format "%wx%h" "#{@d2.avatar.path(:thumb)}"`.chomp
369
339
 
370
- @dummy.avatar = "not a valid file but not nil"
371
- assert_equal File.basename(@file.path), @dummy.avatar_file_name
372
340
  assert @dummy.valid?
373
341
  assert @dummy.save
374
342
 
@@ -407,13 +375,13 @@ class IntegrationTest < Test::Unit::TestCase
407
375
  end
408
376
  end
409
377
 
410
- should "know the difference between good files, bad files, and not files" do
411
- expected = @dummy.avatar.to_file
412
- @dummy.avatar = "not a file"
413
- assert @dummy.valid?
414
- assert_equal expected.path, @dummy.avatar.path
415
- expected.close
378
+ should "not abide things that don't have adapters" do
379
+ assert_raises(Paperclip::AdapterRegistry::NoHandlerError) do
380
+ @dummy.avatar = "not a file"
381
+ end
382
+ end
416
383
 
384
+ should "not be ok with bad files" do
417
385
  @dummy.avatar = @bad_file
418
386
  assert ! @dummy.valid?
419
387
  end
@@ -429,31 +397,13 @@ class IntegrationTest < Test::Unit::TestCase
429
397
 
430
398
  should "be able to reload without saving and not have the file disappear" do
431
399
  @dummy.avatar = @file
432
- assert @dummy.save
400
+ assert @dummy.save, @dummy.errors.full_messages.inspect
433
401
  @dummy.avatar.clear
434
402
  assert_nil @dummy.avatar_file_name
435
403
  @dummy.reload
436
404
  assert_equal "5k.png", @dummy.avatar_file_name
437
405
  end
438
406
 
439
- [000,002,022].each do |umask|
440
- context "when the umask is #{umask}" do
441
- setup do
442
- @umask = File.umask umask
443
- end
444
-
445
- teardown do
446
- File.umask @umask
447
- end
448
-
449
- should "respect the current umask" do
450
- @dummy.avatar = @file
451
- @dummy.save
452
- assert_equal 0666&~umask, 0666&File.stat(@dummy.avatar.path).mode
453
- end
454
- end
455
- end
456
-
457
407
  context "that is assigned its file from another Paperclip attachment" do
458
408
  setup do
459
409
  @dummy2 = Dummy.new
@@ -462,15 +412,17 @@ class IntegrationTest < Test::Unit::TestCase
462
412
  @dummy2.save
463
413
  end
464
414
 
415
+ teardown { @file2.close }
416
+
465
417
  should "work when assigned a file" do
466
418
  assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
467
419
  `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
468
420
 
469
421
  assert @dummy.avatar = @dummy2.avatar
470
422
  @dummy.save
423
+ assert_equal @dummy.avatar_file_name, @dummy2.avatar_file_name
471
424
  assert_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
472
425
  `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
473
- assert_equal @dummy.avatar_file_name, @dummy2.avatar_file_name
474
426
  end
475
427
  end
476
428
 
@@ -482,16 +434,13 @@ class IntegrationTest < Test::Unit::TestCase
482
434
  has_many :attachments, :class_name => 'Dummy'
483
435
  end
484
436
 
437
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
485
438
  @dummy = Dummy.new
486
- @dummy.avatar = File.new(File.join(File.dirname(__FILE__),
487
- "fixtures",
488
- "5k.png"), 'rb')
439
+ @dummy.avatar = @file
489
440
  end
490
441
 
491
442
  should "should not error when saving" do
492
- assert_nothing_raised do
493
- @dummy.save!
494
- end
443
+ @dummy.save!
495
444
  end
496
445
  end
497
446
 
@@ -522,7 +471,6 @@ class IntegrationTest < Test::Unit::TestCase
522
471
  :medium => "100x100",
523
472
  :thumb => ["32x32#", :gif] },
524
473
  :storage => :s3,
525
- :whiny_thumbnails => true,
526
474
  :s3_credentials => File.new(File.join(File.dirname(__FILE__), "s3.yml")),
527
475
  :default_style => :medium,
528
476
  :bucket => ENV['S3_TEST_BUCKET'],
@@ -538,6 +486,12 @@ class IntegrationTest < Test::Unit::TestCase
538
486
  @files_on_s3 = s3_files_for @dummy.avatar
539
487
  end
540
488
 
489
+ teardown do
490
+ @file.close
491
+ @bad_file.close
492
+ @files_on_s3.values.each(&:close)
493
+ end
494
+
541
495
  context 'assigning itself to a new model' do
542
496
  setup do
543
497
  @d2 = Dummy.new
@@ -551,7 +505,6 @@ class IntegrationTest < Test::Unit::TestCase
551
505
  end
552
506
 
553
507
  should "have the same contents as the original" do
554
- @file.rewind
555
508
  assert_equal @file.read, @files_on_s3[:original].read
556
509
  end
557
510