Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
S3 features passing and basic attempt to separate s3-implementation-s…
Browse files Browse the repository at this point in the history
…pecific methods
  • Loading branch information
Jon Yurek committed Jul 29, 2010
1 parent 85c65d3 commit b8aee5f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
12 changes: 10 additions & 2 deletions features/s3.feature
Expand Up @@ -7,13 +7,21 @@ Feature: Running paperclip in a Rails app using basic S3 support
class User < ActiveRecord::Base
has_attached_file :avatar,
:storage => :s3,
:path => "/:attachment/:id/:style/:filename",
:s3_credentials => Rails.root.join("config/s3.yml")
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
And I fill in "user_name" with "something"
And I attach the file "test/fixtures/5k.png" to "user_avatar"
And I press "Submit"
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 the file at "http://s3.amazonaws.com/paperclip/system/avatars/1/original/5k.png" is the same as "test/fixtures/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/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png"
9 changes: 9 additions & 0 deletions features/step_definitions/s3_steps.rb
@@ -0,0 +1,9 @@
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
25 changes: 25 additions & 0 deletions features/support/s3.rb
@@ -0,0 +1,25 @@
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)
3 changes: 2 additions & 1 deletion lib/paperclip/storage.rb
Expand Up @@ -144,7 +144,8 @@ def self.extended base
@s3_headers = @options[:s3_headers] || {}
@s3_host_alias = @options[:s3_host_alias]
unless @url.to_s.match(/^:s3.*url$/)
@url = ":s3_path_url"
@path = @path.gsub(/:url/, @url)
@url = ":s3_path_url"
end
AWS::S3::Base.establish_connection!( @s3_options.merge(
:access_key_id => @s3_credentials[:access_key_id],
Expand Down

0 comments on commit b8aee5f

Please sign in to comment.