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 1 commit
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 => 120

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.
Put a comma after the last item of a multiline hash.

Copy link
Contributor

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.

While we change this file, can we change this whole hash to 1.9 syntax please?

Put a comma after the last item of a multiline hash.

Let's do this, too. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Where do we get the 120 default value from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where do we get the 120 default value from?

You're right, I changed it to nil.

Put a comma after the last item of a multiline hash.

Actually, trailing commas are not preferred: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, trailing commas are not preferred: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas.

It's fine, as we are not making it worse in this PR, but paperclip subscribes to thoughtbot guidelines, encoded in Hound CI: https://github.com/thoughtbot/guides/blob/master/style/ruby/sample.rb#L46-L59.

}
end

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

def download_content
open(@target)
open(@target, read_timeout: Paperclip.options[:read_timeout])
end

def cache_current_values
Expand Down
17 changes: 17 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,21 @@
end
end

describe "#download_content" do
before do
Paperclip.options[:read_timeout] = 240
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

it "calls open with given read_timeout" do
@subject.expects(:open).with(@uri, read_timeout: 240).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.

end