Commit 2dcb1766 by ralph Committed by Jon Yurek

allow to specify a wildcard host to distribute requests across multiple subdomains

parent 28746ecf
......@@ -71,7 +71,8 @@ module Paperclip
def public_url(style = default_style)
if @fog_host
"#{@fog_host}/#{path(style)}"
host = (@fog_host =~ /%d/) ? @fog_host % (path(style).hash % 4) : @fog_host
"#{host}/#{path(style)}"
else
directory.files.new(:key => path(style)).public_url
end
......
......@@ -101,6 +101,26 @@ class FogTest < Test::Unit::TestCase
end
end
context "with a fog_host that includes a wildcard placeholder" do
setup do
rebuild_model(
:fog_directory => @fog_directory,
:fog_credentials => @credentials,
:fog_host => 'http://img%d.example.com',
:fog_public => true,
:path => ":attachment/:basename.:extension",
:storage => :fog
)
@dummy = Dummy.new
@dummy.avatar = StringIO.new('.')
@dummy.save
end
should "provide a public url" do
assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/stringio\.txt\?\d*$/
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