mirror of
https://github.com/kemko/paperclip.git
synced 2026-01-01 16:05:40 +03:00
Close file opened by open-uri
This commit is contained in:
@@ -101,7 +101,9 @@ module Paperclip
|
|||||||
return unless synced_to?(self.class.main_store_id)
|
return unless synced_to?(self.class.main_store_id)
|
||||||
|
|
||||||
if self.class.download_by_url
|
if self.class.download_by_url
|
||||||
create_tempfile(URI.parse(presigned_url(style)).open.read)
|
URI.parse(presigned_url(style)).open do |tempfile|
|
||||||
|
create_tempfile(tempfile.read)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
download_from_store(self.class.main_store_id, style_key)
|
download_from_store(self.class.main_store_id, style_key)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -117,6 +117,27 @@ class NoCacheS3Test < Test::Unit::TestCase
|
|||||||
# Paperclip.expects(:log).with { puts "Log: #{_1}"; true }.at_least(3)
|
# Paperclip.expects(:log).with { puts "Log: #{_1}"; true }.at_least(3)
|
||||||
assert_no_leftover_tmp { @instance.avatar.reprocess! }
|
assert_no_leftover_tmp { @instance.avatar.reprocess! }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with download_by_url" do
|
||||||
|
setup do
|
||||||
|
@instance.avatar.class.instance_variable_set(:@download_by_url, true)
|
||||||
|
@instance.avatar.stubs(:presigned_url).returns("http://example.com/some_file") # чтобы не стабать store.object.presigned_uri
|
||||||
|
require 'open-uri'
|
||||||
|
# правильнее было бы webmock притащить и сам запрос застабить, но ради одного теста жирновато
|
||||||
|
Net::HTTP.any_instance.stubs(:start).yields(nil)
|
||||||
|
resp = Net::HTTPSuccess.new(1.1, 200, 'ok')
|
||||||
|
str = @gif_pixel.dup
|
||||||
|
str.stubs(:clear) # чтобы не попортить вторым вызовом
|
||||||
|
# начиная с OpenURI::Buffer::StringMax open-uri генерит tempfile
|
||||||
|
resp.stubs(:read_body).multiple_yields(str, "\0" * OpenURI::Buffer::StringMax)
|
||||||
|
Net::HTTP.any_instance.stubs(:request).yields(resp)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "delete tmp files" do
|
||||||
|
@store1_stub.expects(:put_object).times(1 + (@instance.avatar.options[:styles].keys - [:original]).size)
|
||||||
|
assert_no_leftover_tmp { @instance.avatar.reprocess! }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with delayed_paperclip process_in_background" do # rubocop:disable Style/MultilineIfModifier
|
context "with delayed_paperclip process_in_background" do # rubocop:disable Style/MultilineIfModifier
|
||||||
|
|||||||
Reference in New Issue
Block a user