Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
9223a917
Commit
9223a917
authored
Jul 22, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored the rails app setups into a combined step.
parent
9da8f322
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
57 deletions
+66
-57
features/basic.feature
+1
-18
features/s3.feature
+4
-28
features/step_definitions/html_steps.rb
+8
-2
features/step_definitions/rails_steps.rb
+48
-4
features/support/rails.rb
+1
-4
lib/paperclip/storage.rb
+4
-1
No files found.
features/basic.feature
View file @
9223a917
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"
...
...
features/s3.feature
View file @
9223a917
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"
features/step_definitions/html_steps.rb
View file @
9223a917
...
...
@@ -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
features/step_definitions/rails_steps.rb
View file @
9223a917
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
...
...
features/support/rails.rb
View file @
9223a917
...
...
@@ -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'
lib/paperclip/storage.rb
View file @
9223a917
...
...
@@ -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
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment