Commit 431d1e8b by Sergey Novikov Committed by Tute Costa

Add read_timeout option to UriAdapter download_content method (#2232)

* Add `read_timeout` option to `UriAdapter#download_content` method
* Default `read_timeout` is `nil`
* Update NEWS
parent ea68f3f1
master:
* Improvement: Add `read_timeout` configuration for URI Adapter download_content method.
* README adjustments for Ruby beginners (add links, elucidate model in Quick Start)
* Bugfix: Now it's possible to save images from URLs with special characters [#1932]
* Fix a nil error in content type validation matcher [#1910]
......
......@@ -97,7 +97,8 @@ module Paperclip
:log_command => true,
:swallow_stderr => true,
:content_type_mappings => {},
:use_exif_orientation => true
:use_exif_orientation => true,
:read_timeout => nil
}
end
......
......@@ -14,7 +14,9 @@ module Paperclip
private
def download_content
open(@target)
options = { read_timeout: Paperclip.options[:read_timeout] }.compact
open(@target, **options)
end
def cache_current_values
......
......@@ -99,4 +99,31 @@ describe Paperclip::UriAdapter do
end
end
describe "#download_content" do
before do
Paperclip::UriAdapter.any_instance.stubs(:open).returns(StringIO.new("xxx"))
@uri = URI.parse("https://github.com/thoughtbot/paper:clip.jpg")
@subject = Paperclip.io_adapters.for(@uri)
end
after do
@subject.send(:download_content)
end
context "with default read_timeout" do
it "calls open without options" do
@subject.expects(:open).with(@uri, {}).at_least_once
end
end
context "with custom read_timeout" do
before do
Paperclip.options[:read_timeout] = 120
end
it "calls open with read_timeout option" do
@subject.expects(:open).with(@uri, read_timeout: 120).at_least_once
end
end
end
end
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