Permalink
Browse files

Merge commit 'orig-paperclip/master'

  • Loading branch information...
2 parents 42a4325 + a23c21e commit bbfaefe4f9e3f6e18ea2fe10f14f986f20beb087 thedarkone committed Feb 3, 2009
View
3 lib/paperclip.rb
@@ -208,7 +208,8 @@ def has_attached_file name, options = {}
end
validates_each(name) do |record, attr, value|
- value.send(:flush_errors) unless value.valid?
+ attachment = record.attachment_for(name)
+ attachment.send(:flush_errors) unless attachment.valid?
end
end
View
9 lib/paperclip/attachment.rb
@@ -91,6 +91,7 @@ def assign uploaded_file
@dirty = true
+ solidify_style_definitions
post_process if valid?
# Reset the file size if the original file was reprocessed.
@@ -314,6 +315,14 @@ def normalize_style_definition #:nodoc:
end
end
+ def solidify_style_definitions #:nodoc:
+ @styles.each do |name, args|
+ if @styles[name][:geometry].respond_to?(:call)
+ @styles[name][:geometry] = @styles[name][:geometry].call(instance)
+ end
+ end
+ end
+
def initialize_storage #:nodoc:
@storage_module = Paperclip::Storage.const_get(@storage.to_s.capitalize)
self.extend(@storage_module)
View
11 lib/paperclip/storage.rb
@@ -72,6 +72,9 @@ def flush_deletes #:nodoc:
end
rescue Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR
# Stop trying to remove parent directories
+ rescue SystemCallError => e
+ logger.info("[paperclip] There was an unexpected error while deleting directories: #{e.class}")
+ # Ignore it
end
end
@queued_for_delete = []
@@ -127,11 +130,11 @@ def self.extended base
require 'right_aws'
base.instance_eval do
@s3_credentials = parse_credentials(@options[:s3_credentials])
- @bucket = @options[:bucket] || @s3_credentials[:bucket]
- @s3_options = @options[:s3_options] || {}
+ @bucket = @options[:bucket] || @s3_credentials[:bucket]
+ @s3_options = @options[:s3_options] || {}
@s3_permissions = @options[:s3_permissions] || 'public-read'
- @s3_protocol = @options[:s3_protocol] || (@s3_permissions == 'public-read' ? 'http' : 'https')
- @s3_headers = @options[:s3_headers] || {}
+ @s3_protocol = @options[:s3_protocol] || (@s3_permissions == 'public-read' ? 'http' : 'https')
+ @s3_headers = @options[:s3_headers] || {}
@url = ":s3_path_url" unless @url.to_s.match(/^:s3.*url$/)
end
base.class.interpolations[:s3_path_url] = lambda do |attachment, style|
View
11 shoulda_macros/paperclip.rb
@@ -31,16 +31,17 @@ def should_validate_attachment_presence name
@attachment.assign(nil)
end
should "have a :presence validation error" do
- assert @assignment.errors[:presence]
+ assert @attachment.errors[:presence]
end
end
context "when the assignment is valid" do
setup do
+ @file = StringIO.new(".")
@attachment = klass.new.send(name)
- @attachment.assign(nil)
+ @attachment.assign(@file)
end
should "have a :presence validation error" do
- assert ! @assignment.errors[:presence]
+ assert ! @attachment.errors[:presence]
end
end
end
@@ -65,7 +66,7 @@ class << @file; attr_accessor :content_type; end
@attachment.assign(@file)
end
should "not have a :content_type validation error" do
- assert ! @assignment.errors[:content_type]
+ assert ! @attachment.errors[:content_type]
end
end
end
@@ -79,7 +80,7 @@ class << @file; attr_accessor :content_type; end
@attachment.assign(@file)
end
should "have a :content_type validation error" do
- assert @assignment.errors[:content_type]
+ assert @attachment.errors[:content_type]
end
end
end
View
15 test/attachment_test.rb
@@ -182,8 +182,19 @@ def thumb; "-thumb"; end
@attachment = Dummy.new.avatar
end
- should "have the correct geometry" do
- assert_equal "50x50#", @attachment.styles[:normal][:geometry]
+ should "not run the procs immediately" do
+ assert_kind_of Proc, @attachment.styles[:normal][:geometry]
+ end
+
+ context "when assigned" do
+ setup do
+ @file = StringIO.new(".")
+ @attachment.assign(@file)
+ end
+
+ should "have the correct geometry" do
+ assert_equal "50x50#", @attachment.styles[:normal][:geometry]
+ end
end
end
end
View
4 test/integration_test.rb
@@ -106,6 +106,10 @@ class IntegrationTest < Test::Unit::TestCase
assert ! File.exists?(File.dirname(@saved_path))
assert ! File.exists?(File.dirname(File.dirname(@saved_path)))
end
+
+ before_should "not die if an unexpected SystemCallError happens" do
+ FileUtils.stubs(:rmdir).raises(Errno::EEXIST)
+ end
end
end
end

0 comments on commit bbfaefe

Please sign in to comment.