Commit 9ae8455b by Geoff Harcourt Committed by Jon Yurek

#expiring_url returns public_url when not using AWS to prevent exceptions when…

#expiring_url returns public_url when not using AWS to prevent exceptions when Fog Local is swapped for Fog AWS in development.
parent e3556b9b
...@@ -128,10 +128,14 @@ module Paperclip ...@@ -128,10 +128,14 @@ module Paperclip
end end
def expiring_url(time = (Time.now + 3600), style = default_style) def expiring_url(time = (Time.now + 3600), style = default_style)
expiring_url = directory.files.get_http_url(path(style), time) if fog_credentials[:provider] == 'AWS'
expiring_url = directory.files.get_http_url(path(style), time)
if @options[:fog_host] if @options[:fog_host]
expiring_url.gsub!(/#{host_name_for_directory}/, dynamic_fog_host_for_style(style)) expiring_url.gsub!(/#{host_name_for_directory}/, dynamic_fog_host_for_style(style))
end
else
expiring_url = public_url
end end
return expiring_url return expiring_url
......
require './test/helper' require './test/helper'
require 'fog' require 'fog'
Fog.mock!
class FogTest < Test::Unit::TestCase class FogTest < Test::Unit::TestCase
context "" do context "" do
setup { Fog.mock! }
context "with credentials provided in a path string" do context "with credentials provided in a path string" do
setup do setup do
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" }, rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
...@@ -404,4 +404,29 @@ class FogTest < Test::Unit::TestCase ...@@ -404,4 +404,29 @@ class FogTest < Test::Unit::TestCase
end end
end end
context "when using local storage" do
setup do
Fog.unmock!
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :fog,
:url => '/:attachment/:filename',
:fog_directory => "paperclip",
:fog_credentials => { :provider => :local, :local_root => "." },
:fog_host => 'localhost'
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
end
teardown do
@file.close
Fog.mock!
end
should "return the public url in place of the expiring url" do
assert_match @dummy.avatar.public_url, @dummy.avatar.expiring_url
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