Commit d177c8f8 by Jon Yurek

has_attached_file respects :whiny_thumbnails. Added…

has_attached_file respects :whiny_thumbnails. Added validates_attachment_thumbnails which does the same thing.
parent 7dd35f58
......@@ -169,6 +169,11 @@ module Paperclip
end
end
# Adds errors if thumbnail creation fails. The same as specifying :whiny_thumbnails => true.
def validates_attachment_thumbnails name, options = {}
attachment_definitions[name][:whiny_thumbnails] = true
end
# Places ActiveRecord-style validations on the presence of a file.
def validates_attachment_presence name, options = {}
attachment_definitions[name][:validations] << lambda do |attachment, instance|
......
......@@ -33,6 +33,7 @@ module Paperclip
@validations = options[:validations]
@default_style = options[:default_style]
@storage = options[:storage]
@whiny_thumbnails = options[:whiny_thumbnails]
@options = options
@queued_for_delete = []
@queued_for_write = {}
......
......@@ -82,7 +82,7 @@ class GeometryTest < Test::Unit::TestCase
should "not generate from a bad file" do
file = "/home/This File Does Not Exist.omg"
assert_raise(Paperclip::NotIdentifiedByImageMagick){ @geo = Paperclip::Geometry.from_file(file) }
assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
end
[['vertical', 900, 1440, true, false, false, 1440, 900, 0.625],
......
......@@ -18,11 +18,54 @@ class IntegrationTest < Test::Unit::TestCase
end
end
context "A model with no attachment validation" do
setup do
rebuild_model :styles => { :large => "300x300>",
:medium => "100x100",
:thumb => ["32x32#", :gif] },
:default_style => :medium,
:url => "/:attachment/:class/:style/:id/:basename.:extension",
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy = Dummy.new
end
should "have its definition return false when asked about whiny_thumbnails" do
assert ! Dummy.attachment_definitions[:avatar][:whiny_thumbnails]
end
context "when validates_attachment_thumbnails is called" do
setup do
Dummy.validates_attachment_thumbnails :avatar
end
should "have its definition return true when asked about whiny_thumbnails" do
assert_equal true, Dummy.attachment_definitions[:avatar][:whiny_thumbnails]
end
end
context "redefined to have attachment validations" do
setup do
rebuild_model :styles => { :large => "300x300>",
:medium => "100x100",
:thumb => ["32x32#", :gif] },
:whiny_thumbnails => true,
:default_style => :medium,
:url => "/:attachment/:class/:style/:id/:basename.:extension",
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
end
should "have its definition return true when asked about whiny_thumbnails" do
assert_equal true, Dummy.attachment_definitions[:avatar][:whiny_thumbnails]
end
end
end
context "A model with a filesystem attachment" do
setup do
rebuild_model :styles => { :large => "300x300>",
:medium => "100x100",
:thumb => ["32x32#", :gif] },
:whiny_thumbnails => true,
:default_style => :medium,
:url => "/:attachment/:class/:style/:id/:basename.:extension",
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
......@@ -103,7 +146,9 @@ class IntegrationTest < Test::Unit::TestCase
assert ! @dummy.valid?
@dummy.avatar = nil
assert @dummy.valid?
end
should "know the difference between good files, bad files, not files, and nil when validating" do
Dummy.validates_attachment_presence :avatar
@d2 = Dummy.find(@dummy.id)
@d2.avatar = @file
......@@ -142,6 +187,7 @@ class IntegrationTest < Test::Unit::TestCase
:medium => "100x100",
:thumb => ["32x32#", :gif] },
:storage => :s3,
:whiny_thumbnails => true,
# :s3_options => {:logger => Logger.new(StringIO.new)},
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "s3.yml")),
:default_style => :medium,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment