Commit 84a5d41c by Thomas Ingram

Respect dynamic fog directory option

`Paperclip::Storage::Fog#host_name_for_directory` assumes a String-like
object is set and doesn't check if `@options[:fog_directory]` is
callable, while `Paperclip::Storage::Fog#directory` does. This extracts
a new method with the condition and refactors the other two methods to
call it.

Fixes #2018, #2093.
parent 0ae039d2
* Bugfix: Dynamic fog directory option is now respected
5.0.0.beta1
* Drop support to end-of-life'd ruby 2.0.
......
......@@ -195,10 +195,10 @@ module Paperclip
end
def host_name_for_directory
if @options[:fog_directory].to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
"#{@options[:fog_directory]}.s3.amazonaws.com"
if directory_name.to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
"#{directory_name}.s3.amazonaws.com"
else
"s3.amazonaws.com/#{@options[:fog_directory]}"
"s3.amazonaws.com/#{directory_name}"
end
end
......@@ -224,13 +224,15 @@ module Paperclip
end
def directory
dir = if @options[:fog_directory].respond_to?(:call)
@directory ||= connection.directories.new(key: directory_name)
end
def directory_name
if @options[:fog_directory].respond_to?(:call)
@options[:fog_directory].call(self)
else
@options[:fog_directory]
end
@directory ||= connection.directories.new(:key => dir)
end
def scheme
......
......@@ -418,6 +418,9 @@ describe Paperclip::Storage::Fog do
assert @connection.directories.get(@dynamic_fog_directory).inspect
end
it "provides an url using dynamic bucket name" do
assert_match(/^https:\/\/dynamicpaperclip.s3.amazonaws.com\/avatars\/5k.png\?\d*$/, @dummy.avatar.url)
end
end
context "with a proc for the fog_host evaluating a model method" 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