Commit 066c1069 by Jon Yurek

Added test to make sure no unnecessary connections are made to S3.

Changed S3 URL generation to a manual interpolation instead of RightAws's public_link method.
parent dbd63a29
...@@ -53,7 +53,7 @@ module Paperclip ...@@ -53,7 +53,7 @@ module Paperclip
@url = ":s3_url" @url = ":s3_url"
end end
base.class.interpolations[:s3_url] = lambda do |attachment, style| base.class.interpolations[:s3_url] = lambda do |attachment, style|
attachment.to_io(style).public_link "https://s3.amazonaws.com/#{attachment.bucket_name}#{attachment.path(style)}"
end end
end end
...@@ -67,6 +67,10 @@ module Paperclip ...@@ -67,6 +67,10 @@ module Paperclip
@s3_bucket ||= s3.bucket(@bucket, true, @s3_permissions) @s3_bucket ||= s3.bucket(@bucket, true, @s3_permissions)
end end
def bucket_name
@bucket
end
def parse_credentials creds def parse_credentials creds
creds = find_credentials(creds).stringify_keys creds = find_credentials(creds).stringify_keys
(creds[ENV['RAILS_ENV']] || creds).symbolize_keys (creds[ENV['RAILS_ENV']] || creds).symbolize_keys
......
...@@ -46,6 +46,7 @@ class StorageTest < Test::Unit::TestCase ...@@ -46,6 +46,7 @@ class StorageTest < Test::Unit::TestCase
setup do setup do
rebuild_model :storage => :s3, rebuild_model :storage => :s3,
:bucket => "testing", :bucket => "testing",
:path => "/:attachment/:style/:basename.:extension",
:s3_credentials => { :s3_credentials => {
'access_key_id' => "12345", 'access_key_id' => "12345",
'secret_access_key' => "54321" 'secret_access_key' => "54321"
...@@ -67,6 +68,12 @@ class StorageTest < Test::Unit::TestCase ...@@ -67,6 +68,12 @@ class StorageTest < Test::Unit::TestCase
@dummy.avatar = @file @dummy.avatar = @file
end end
should "not get a bucket to get a URL" do
@dummy.avatar.expects(:s3).never
@dummy.avatar.expects(:s3_bucket).never
assert_equal "https://s3.amazonaws.com/testing/avatars/original/5k.png", @dummy.avatar.url
end
context "and saved" do context "and saved" do
setup do setup do
@s3_mock = stub @s3_mock = stub
......
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