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
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
56 deletions
+65
-56
features/basic.feature
+1
-18
features/s3.feature
+4
-28
features/step_definitions/html_steps.rb
+7
-1
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
Feature
:
Running paperclip in a Rails app
Scenario
:
Basic utilization
Scenario
:
Basic utilization
Given
I generate a rails application
Given
I have a rails application
And I have a "users" resource with "name
:
string"
And
I run
"script/generate paperclip user avatar"
And
I save the following as
"app/models/user.rb"
And
I save the following as
"app/models/user.rb"
"""
"""
class User < ActiveRecord::Base
class User < ActiveRecord::Base
has_attached_file :avatar
has_attached_file :avatar
end
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
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"
...
...
features/s3.feature
View file @
9223a917
Feature
:
Running paperclip in a Rails app using basic S3 support
Feature
:
Running paperclip in a Rails app using basic S3 support
Scenario
:
Basic utilization
Scenario
:
Basic utilization
Given
I generate a rails application
Given
I have a rails application
And I have a "users" resource with "name
:
string"
And
I run
"script/generate paperclip user avatar"
And
I save the following as
"app/models/user.rb"
And
I save the following as
"app/models/user.rb"
"""
"""
class User < ActiveRecord::Base
class User < ActiveRecord::Base
has_attached_file :avatar,
has_attached_file :avatar,
:storage => :s3,
:storage => :s3,
:bucket => "jyurek",
:s3_credentials => Rails.root.join("config/s3.yml")
:s3_credentials => "config/s3.yml"
end
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
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
:
//
paperclip.s3.amazonaws.com
/system/avatars/1/original/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
:
//
paperclip.s3.amazonaws.com
/system/avatars/1/original/5k.png"
is
the
same
as
"test/fixtures/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|
...
@@ -3,6 +3,12 @@ Then %r{I should see an image with a path of "([^"]*)"} do |path|
end
end
Then
%r{^the file at "([^"]*)" is the same as "([^"]*)"$}
do
|
web_file
,
path
|
Then
%r{^the file at "([^"]*)" is the same as "([^"]*)"$}
do
|
web_file
,
path
|
expected
=
IO
.
read
(
path
)
actual
=
if
web_file
.
match
%r{^https?://}
Net
::
HTTP
.
get
(
URI
.
parse
(
web_file
))
else
visit
(
web_file
)
visit
(
web_file
)
page
.
body
.
should
==
IO
.
read
(
path
)
page
.
body
end
actual
.
should
==
expected
end
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
Given
%r{I generate a rails application}
do
FileUtils
.
rm_rf
TEMP_ROOT
FileUtils
.
rm_rf
TEMP_ROOT
FileUtils
.
mkdir_p
TEMP_ROOT
FileUtils
.
mkdir_p
TEMP_ROOT
Dir
.
chdir
(
TEMP_ROOT
)
do
Dir
.
chdir
(
TEMP_ROOT
)
do
`rails _2.3.8_
#{
APP_NAME
}
`
`rails _2.3.8_
#{
APP_NAME
}
`
end
end
ENV
[
'RAILS_ENV'
]
=
'test'
end
end
When
%r{I save the following as "([^"]*)"}
do
|
path
,
string
|
When
%r{I save the following as "([^"]*)"}
do
|
path
,
string
|
...
@@ -12,13 +46,23 @@ 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
)
}
File
.
open
(
File
.
join
(
CUC_RAILS_ROOT
,
path
),
'w'
)
{
|
file
|
file
.
write
(
string
)
}
end
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
%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"
When
"the rails application is running"
end
end
When
%r{
the rails application is prepped$
}
do
When
%r{
I reset the database
}
do
When
%{I run "rake db:create db:migrate"}
When
%{I run "rake db:
drop db:
create db:migrate"}
end
end
When
%r{the rails application is running}
do
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__), '..', '..'
...
@@ -2,7 +2,4 @@ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'
TEMP_ROOT
=
File
.
join
(
PROJECT_ROOT
,
'tmp'
).
freeze
TEMP_ROOT
=
File
.
join
(
PROJECT_ROOT
,
'tmp'
).
freeze
APP_NAME
=
'testapp'
.
freeze
APP_NAME
=
'testapp'
.
freeze
CUC_RAILS_ROOT
=
File
.
join
(
TEMP_ROOT
,
APP_NAME
).
freeze
CUC_RAILS_ROOT
=
File
.
join
(
TEMP_ROOT
,
APP_NAME
).
freeze
ENV
[
'RAILS_ENV'
]
=
'test'
Before
do
Dir
.
chdir
(
PROJECT_ROOT
)
end
lib/paperclip/storage.rb
View file @
9223a917
...
@@ -143,7 +143,10 @@ module Paperclip
...
@@ -143,7 +143,10 @@ module Paperclip
@s3_protocol
=
@options
[
:s3_protocol
]
||
(
@s3_permissions
==
:public_read
?
'http'
:
'https'
)
@s3_protocol
=
@options
[
:s3_protocol
]
||
(
@s3_permissions
==
:public_read
?
'http'
:
'https'
)
@s3_headers
=
@options
[
:s3_headers
]
||
{}
@s3_headers
=
@options
[
:s3_headers
]
||
{}
@s3_host_alias
=
@options
[
:s3_host_alias
]
@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
(
AWS
::
S3
::
Base
.
establish_connection!
(
@s3_options
.
merge
(
:access_key_id
=>
@s3_credentials
[
:access_key_id
],
:access_key_id
=>
@s3_credentials
[
:access_key_id
],
:secret_access_key
=>
@s3_credentials
[
:secret_access_key
]
: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