Commit b8aee5f7 by Jon Yurek

S3 features passing and basic attempt to separate s3-implementation-specific methods

parent 85c65d3d
...@@ -7,13 +7,21 @@ Feature: Running paperclip in a Rails app using basic S3 support ...@@ -7,13 +7,21 @@ Feature: Running paperclip in a Rails app using basic S3 support
class User < ActiveRecord::Base class User < ActiveRecord::Base
has_attached_file :avatar, has_attached_file :avatar,
:storage => :s3, :storage => :s3,
:path => "/:attachment/:id/:style/:filename",
:s3_credentials => Rails.root.join("config/s3.yml") :s3_credentials => Rails.root.join("config/s3.yml")
end end
""" """
And I validate my S3 credentials
And I save the following as "config/s3.yml"
"""
bucket: <%= ENV['PAPERCLIP_TEST_BUCKET'] || 'paperclip' %>
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
"""
When I visit /users/new When I visit /users/new
And I fill in "user_name" with "something" And I fill in "user_name" with "something"
And I attach the file "test/fixtures/5k.png" to "user_avatar" And I attach the file "test/fixtures/5k.png" to "user_avatar"
And I press "Submit" And I press "Submit"
Then I should see "Name: something" Then I should see "Name: something"
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/system/avatars/1/original/5k.png" And I should see an image with a path of "http://s3.amazonaws.com/paperclip/avatars/1/original/5k.png"
And the file at "http://s3.amazonaws.com/paperclip/system/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png" And the file at "http://s3.amazonaws.com/paperclip/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png"
Given /I validate my S3 credentials/ do
key = ENV['AWS_ACCESS_KEY_ID']
secret = ENV['AWS_SECRET_ACCESS_KEY']
key.should_not be_nil
secret.should_not be_nil
assert_credentials(key, secret)
end
module AWSS3Methods
def load_s3
begin
require 'aws/s3'
rescue LoadError => e
fail "You do not have aws-s3 installed."
end
end
def assert_credentials(key, secret)
load_s3
begin
AWS::S3::Base.establish_connection!(
:access_key_id => key,
:secret_access_key => secret
)
AWS::S3::Service.buckets
rescue AWS::S3::ResponseError => e
fail "Could not connect using AWS credentials in AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. " +
"Please make sure these are set in your environment."
end
end
end
World(AWSS3Methods)
...@@ -144,7 +144,8 @@ module Paperclip ...@@ -144,7 +144,8 @@ module Paperclip
@s3_headers = @options[:s3_headers] || {} @s3_headers = @options[:s3_headers] || {}
@s3_host_alias = @options[:s3_host_alias] @s3_host_alias = @options[:s3_host_alias]
unless @url.to_s.match(/^:s3.*url$/) unless @url.to_s.match(/^:s3.*url$/)
@url = ":s3_path_url" @path = @path.gsub(/:url/, @url)
@url = ":s3_path_url"
end end
AWS::S3::Base.establish_connection!( @s3_options.merge( AWS::S3::Base.establish_connection!( @s3_options.merge(
:access_key_id => @s3_credentials[:access_key_id], :access_key_id => @s3_credentials[:access_key_id],
......
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