thoughtbot-paperclip 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/paperclip.rb CHANGED
@@ -43,7 +43,7 @@ end
43
43
  # documentation for Paperclip::ClassMethods for more useful information.
44
44
  module Paperclip
45
45
 
46
- VERSION = "2.2.1"
46
+ VERSION = "2.2.2"
47
47
 
48
48
  class << self
49
49
  # Provides configurability to Paperclip. There are a number of options available, such as:
@@ -255,7 +255,7 @@ module Paperclip
255
255
  valid_types = [options[:content_type]].flatten
256
256
 
257
257
  unless attachment.original_filename.blank?
258
- unless options[:content_type].blank?
258
+ unless valid_types.blank?
259
259
  content_type = attachment.instance_read(:content_type)
260
260
  unless valid_types.any?{|t| t === content_type }
261
261
  options[:message] || "is not one of the allowed file types."
@@ -326,11 +326,13 @@ module Paperclip
326
326
  log("Post-processing #{name}")
327
327
  @styles.each do |name, args|
328
328
  begin
329
- @queued_for_write[name] = @queued_for_write[:original]
330
- args[:processors].each do |processor|
331
- @queued_for_write[name] = Paperclip.processor(processor).make(@queued_for_write[name], args)
329
+ raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank?
330
+ @queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor|
331
+ log("Processing #{name} #{file} in the #{processor} processor.")
332
+ Paperclip.processor(processor).make(file, args)
332
333
  end
333
334
  rescue PaperclipError => e
335
+ log("An error was received while processing: #{e.inspect}")
334
336
  (@errors[:processing] ||= []) << e.message if @whiny
335
337
  end
336
338
  end
@@ -210,6 +210,17 @@ class AttachmentTest < Test::Unit::TestCase
210
210
  end
211
211
  end
212
212
 
213
+ context "An attachment with no processors defined" do
214
+ setup do
215
+ rebuild_model :processors => [], :styles => {:something => 1}
216
+ @dummy = Dummy.new
217
+ @file = StringIO.new("...")
218
+ end
219
+ should "raise when assigned to" do
220
+ assert_raises(RuntimeError){ @dummy.avatar = @file }
221
+ end
222
+ end
223
+
213
224
  context "Assigning an attachment with post_process hooks" do
214
225
  setup do
215
226
  rebuild_model :styles => { :something => "100x100#" }
@@ -177,6 +177,21 @@ class PaperclipTest < Test::Unit::TestCase
177
177
  Dummy.send(:"validates_attachment_#{validation}", :avatar, options)
178
178
  @dummy = Dummy.new
179
179
  end
180
+ context "and assigning nil" do
181
+ setup do
182
+ @dummy.avatar = nil
183
+ @dummy.valid?
184
+ end
185
+ if validation == :presence
186
+ should "have an error on the attachment" do
187
+ assert @dummy.errors.on(:avatar)
188
+ end
189
+ else
190
+ should "not have an error on the attachment" do
191
+ assert_nil @dummy.errors.on(:avatar)
192
+ end
193
+ end
194
+ end
180
195
  context "and assigned a valid file" do
181
196
  setup do
182
197
  @dummy.avatar = valid_file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thoughtbot-paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Yurek