Commit 78cfebd5 by Jon Yurek

Changes from merging with master/3.0

parent 89c8d117
......@@ -51,6 +51,13 @@ Then /^the attachment should have the same content type as the fixture "([^"]*)"
end
end
Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
in_current_dir do
attachment_file_name = `bundle exec #{runner_command} "puts User.last.attachment_file_name"`.strip
attachment_file_name.should == File.name(fixture_path(filename)).to_s
end
end
Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
in_current_dir do
attachment_file_size = `bundle exec #{runner_command} "puts User.last.attachment_file_size"`.strip
......
......@@ -77,6 +77,14 @@ module Paperclip
}
end
def self.io_adapters=(new_registry)
@io_adapters = new_registry
end
def self.io_adapters
@io_adapters ||= Paperclip::AdapterRegistry.new
end
module ClassMethods
# +has_attached_file+ gives the class it is called on an attribute that maps to a file. This
# is typically a file stored somewhere on the filesystem and has been uploaded by a user.
......
......@@ -269,16 +269,6 @@ module Paperclip
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@options[:hash_digest]).new, @options[:hash_secret], data)
end
def generate_fingerprint(source)
if source.respond_to?(:path) && source.path && !source.path.blank?
Digest::MD5.file(source.path).to_s
else
data = source.read
source.rewind if source.respond_to?(:rewind)
Digest::MD5.hexdigest(data)
end
end
# This method really shouldn't be called that often. It's expected use is
# in the paperclip:refresh rake task and that's it. It will regenerate all
# thumbnails forcefully, by reobtaining the original file and going through
......
module Paperclip
class AdapterRegistry
class NoHandlerError < PaperclipError; end
class NoHandlerError < Paperclip::Error; end
attr_reader :registered_handlers
......
......@@ -31,6 +31,11 @@ module Paperclip
@tempfile.read(length, buffer)
end
# We don't use this directly, but aws/sdk does.
def rewind
@tempfile.rewind
end
def eof?
@tempfile.eof?
end
......
......@@ -77,7 +77,6 @@ module Paperclip
def flush_writes
for style, file in @queued_for_write do
log("saving #{path(style)}")
file.rewind
retried = false
begin
directory.files.create(fog_file.merge(
......
......@@ -272,7 +272,6 @@ module Paperclip
@queued_for_write.each do |style, file|
begin
log("saving #{path(style)}")
file.rewind
acl = @s3_permissions[style] || @s3_permissions[:default]
acl = acl.call(self, style) if acl.respond_to?(:call)
write_options = {
......
......@@ -45,7 +45,7 @@ namespace :paperclip do
names = Paperclip::Task.obtain_attachments(klass)
names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
if file = instance.send(name)
if file = Paperclip.io_adapters.for(instance.send(name))
instance.send("#{name}_file_name=", instance.send("#{name}_file_name").strip)
instance.send("#{name}_content_type=", file.content_type.to_s.strip)
instance.send("#{name}_file_size=", file.size) if instance.respond_to?("#{name}_file_size")
......
......@@ -102,19 +102,6 @@ class FogTest < Test::Unit::TestCase
directory.destroy
end
# NOTE: This might not be necessary, watch for this to error
should "always be rewound when returning from #to_file" do
assert_equal 0, @dummy.avatar.to_file.pos
@dummy.avatar.to_file.seek(10)
assert_equal 0, @dummy.avatar.to_file.pos
end
# NOTE: This might not be necessary, watch for this to error
should "rewind file in flush_writes" do
@dummy.avatar.queued_for_write.each { |style, file| file.expects(:rewind).with() }
@dummy.save
end
should "pass the content type to the Fog::Storage::AWS::Files instance" do
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
hash[:content_type]
......
require './test/helper'
require 'aws'
unless ENV["S3_BUCKET"].blank?
class S3LiveTest < Test::Unit::TestCase
context "when assigning an S3 attachment directly to another model" do
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@dummy = Dummy.new
@attachment = Dummy.new.avatar
@file = File.new(fixture_file("5k.png"))
@attachment.assign(@file)
@attachment.save
@attachment2 = Dummy.new.avatar
@attachment2.assign(@file)
@attachment2.save
binding.pry
end
end
context "Generating an expiring url on a nonexistant attachment" do
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
......
......@@ -88,7 +88,6 @@ class S3Test < Test::Unit::TestCase
setup do
rebuild_model :storage => :s3,
#:bucket => "testing", # intentionally left out
:http_proxy => @proxy_settings,
:s3_credentials => {:not => :important}
......@@ -336,18 +335,6 @@ class S3Test < Test::Unit::TestCase
assert_match %r{^avatars/stringio\.txt}, @dummy.avatar.url
end
# NOTE: This might not be necessary, watch for this to error
should "always be rewound when returning from #to_file" do
assert_equal 0, @dummy.avatar.to_file.pos
@dummy.avatar.to_file.seek(10)
assert_equal 0, @dummy.avatar.to_file.pos
end
# NOTE: This might not be necessary, watch for this to error
should "rewind file in flush_writes" do
@dummy.avatar.queued_for_write.each { |style, file| file.expects(:rewind).with() }
@dummy.save
end
end
context "Generating a secure url with an expiration" do
......
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