Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Add read_timeout option to UriAdapter download_content method #2232

Merged
merged 3 commits into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def self.options
:log_command => true,
:swallow_stderr => true,
:content_type_mappings => {},
:use_exif_orientation => true
:use_exif_orientation => true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:read_timeout => nil
}
end

Expand Down
4 changes: 3 additions & 1 deletion lib/paperclip/io_adapters/uri_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def initialize(target)
private

def download_content
open(@target)
options = { read_timeout: Paperclip.options[:read_timeout] }.compact

open(@target, **options)
end

def cache_current_values
Expand Down
27 changes: 27 additions & 0 deletions spec/paperclip/io_adapters/uri_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,31 @@
end
end

describe "#download_content" do
before do
Paperclip::UriAdapter.any_instance.stubs(:open).returns(StringIO.new("xxx"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [82/80]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [82/80]

@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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at block body 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