Skip to content
Browse files

Refactored the rails app setups into a combined step.

  • Loading branch information...
1 parent 9da8f32 commit 9223a917a821731986603e89a9b2e4d1a4fdd68a @jyurek jyurek committed Jul 22, 2010
View
19 features/basic.feature
@@ -1,30 +1,13 @@
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"
View
32 features/s3.feature
@@ -1,43 +1,19 @@
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"
View
10 features/step_definitions/html_steps.rb
@@ -3,6 +3,12 @@
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
View
52 features/step_definitions/rails_steps.rb
@@ -1,24 +1,68 @@
+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|
FileUtils.mkdir_p(File.join(CUC_RAILS_ROOT, File.dirname(path)))
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
View
5 features/support/rails.rb
@@ -2,7 +2,4 @@
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'
View
5 lib/paperclip/storage.rb
@@ -143,7 +143,10 @@ def self.extended base
@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]

0 comments on commit 9223a91

Please sign in to comment.
Something went wrong with that request. Please try again.