Commit 9223a917 by Jon Yurek

Refactored the rails app setups into a combined step.

parent 9da8f322
Feature: Running paperclip in a Rails app
Scenario: Basic utilization
Given I generate a rails application
And I have a "users" resource with "name:string"
And I run "script/generate paperclip user avatar"
Given I have a rails application
And I save the following as "app/models/user.rb"
"""
class User < ActiveRecord::Base
has_attached_file :avatar
end
"""
And I save the following as "app/views/users/new.html.erb"
"""
<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.text_field :name %>
<%= f.file_field :avatar %>
<%= submit_tag "Submit" %>
<% end %>
"""
And I save the following as "app/views/users/show.html.erb"
"""
<p>Name: <%= @user.name %></p>
<p>Avatar: <%= image_tag @user.avatar.url %></p>
"""
And this plugin is available
And the rails application is prepped and running
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"
......
Feature: Running paperclip in a Rails app using basic S3 support
Scenario: Basic utilization
Given I generate a rails application
And I have a "users" resource with "name:string"
And I run "script/generate paperclip user avatar"
Given I have a rails application
And I save the following as "app/models/user.rb"
"""
class User < ActiveRecord::Base
has_attached_file :avatar,
:storage => :s3,
:bucket => "jyurek",
:s3_credentials => "config/s3.yml"
:s3_credentials => Rails.root.join("config/s3.yml")
end
"""
And I save the following as "config/s3.yml"
"""
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
bucket: paperclip
"""
And I save the following as "app/views/users/new.html.erb"
"""
<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.text_field :name %>
<%= f.file_field :avatar %>
<%= submit_tag "Submit" %>
<% end %>
"""
And I save the following as "app/views/users/show.html.erb"
"""
<p>Name: <%= @user.name %></p>
<p>Avatar: <%= image_tag @user.avatar.url %></p>
"""
And this plugin is available
And the rails application is prepped and running
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://paperclip.s3.amazonaws.com/system/avatars/1/original/5k.png"
And the file at "http://paperclip.s3.amazonaws.com/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/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"
......@@ -3,6 +3,12 @@ Then %r{I should see an image with a path of "([^"]*)"} do |path|
end
Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
visit(web_file)
page.body.should == IO.read(path)
expected = IO.read(path)
actual = if web_file.match %r{^https?://}
Net::HTTP.get(URI.parse(web_file))
else
visit(web_file)
page.body
end
actual.should == expected
end
Given "I have a rails application" do
steps %{
Given I generate a rails application
And I have a "users" resource with "name:string"
And I turn off class caching
And I run "script/generate paperclip user avatar"
Given I save the following as "app/models/user.rb"
"""
class User < ActiveRecord::Base
end
"""
And I save the following as "config/s3.yml"
"""
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
bucket: paperclip
"""
And I save the following as "app/views/users/new.html.erb"
"""
<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.text_field :name %>
<%= f.file_field :avatar %>
<%= submit_tag "Submit" %>
<% end %>
"""
And I save the following as "app/views/users/show.html.erb"
"""
<p>Name: <%= @user.name %></p>
<p>Avatar: <%= image_tag @user.avatar.url %></p>
"""
And this plugin is available
And the rails application is prepped and running
}
end
Given %r{I generate a rails application} do
FileUtils.rm_rf TEMP_ROOT
FileUtils.mkdir_p TEMP_ROOT
Dir.chdir(TEMP_ROOT) do
`rails _2.3.8_ #{APP_NAME}`
end
ENV['RAILS_ENV'] = 'test'
end
When %r{I save the following as "([^"]*)"} do |path, string|
......@@ -12,13 +46,23 @@ When %r{I save the following as "([^"]*)"} do |path, string|
File.open(File.join(CUC_RAILS_ROOT, path), 'w') { |file| file.write(string) }
end
When %r{I turn off class caching} do
Dir.chdir(CUC_RAILS_ROOT) do
file = "config/environments/test.rb"
config = IO.read(file)
config.gsub!(%r{^\s*config.cache_classes.*$},
"config.cache_classes = false")
File.open(file, "w"){|f| f.write(config) }
end
end
When %r{the rails application is prepped and running$} do
When "the rails application is prepped"
When "I reset the database"
When "the rails application is running"
end
When %r{the rails application is prepped$} do
When %{I run "rake db:create db:migrate"}
When %r{I reset the database} do
When %{I run "rake db:drop db:create db:migrate"}
end
When %r{the rails application is running} do
......
......@@ -2,7 +2,4 @@ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'
TEMP_ROOT = File.join(PROJECT_ROOT, 'tmp').freeze
APP_NAME = 'testapp'.freeze
CUC_RAILS_ROOT = File.join(TEMP_ROOT, APP_NAME).freeze
Before do
Dir.chdir(PROJECT_ROOT)
end
ENV['RAILS_ENV'] = 'test'
......@@ -143,7 +143,10 @@ module Paperclip
@s3_protocol = @options[:s3_protocol] || (@s3_permissions == :public_read ? 'http' : 'https')
@s3_headers = @options[:s3_headers] || {}
@s3_host_alias = @options[:s3_host_alias]
@url = ":s3_path_url" unless @url.to_s.match(/^:s3.*url$/)
unless @url.to_s.match(/^:s3.*url$/)
@path = @url
@url = ":s3_path_url"
end
AWS::S3::Base.establish_connection!( @s3_options.merge(
:access_key_id => @s3_credentials[:access_key_id],
:secret_access_key => @s3_credentials[:secret_access_key]
......
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