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
898baf2c
Commit
898baf2c
authored
Oct 14, 2011
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add integration test in cucumber to test rake task
parent
7ab5ba66
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
133 additions
and
0 deletions
+133
-0
features/rake_tasks.feature
+63
-0
features/step_definitions/attachment_steps.rb
+70
-0
No files found.
features/rake_tasks.feature
0 → 100644
View file @
898baf2c
Feature
:
Rake tasks
Background
:
Given
I generate a new rails application
And I run a rails generator to generate a "User" scaffold with "name
:
string"
And
I run a paperclip generator to add a paperclip
"attachment"
to the
"User"
model
And
I run a migration
And I add this snippet to the User model
:
"""
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
"""
Scenario
:
Paperclip refresh thumbnails task
When I modify my attachment definition to
:
"""
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
:styles => { :medium => "200x200#" }
"""
And
I upload the fixture
"5k.png"
Then
the attachment
"medium/5k.png"
should have a dimension of 200x200
When I modify my attachment definition to
:
"""
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
:styles => { :medium => "100x100#" }
"""
When I successfully run `bundle exec rake paperclip
:
refresh
:
thumbnails
CLASS=User
--trace`
Then
the attachment
"original/5k.png"
should exist
And
the attachment
"medium/5k.png"
should have a dimension of 100x100
Scenario
:
Paperclip refresh metadata task
When
I upload the fixture
"5k.png"
And
I swap the attachment
"original/5k.png"
with the fixture
"12k.png"
And I successfully run `bundle exec rake paperclip
:
refresh
:
metadat
a
CLASS=User --trace`
Then
the attachment should have the same content type as the fixture
"12k.png"
And
the attachment should have the same file size as the fixture
"12k.png"
Scenario
:
Paperclip refresh missing styles task
When
I upload the fixture
"5k.png"
Then
the attachment file
"original/5k.png"
should exist
And
the attachment file
"medium/5k.png"
should not exist
When I modify my attachment definition to
:
"""
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename",
:styles => { :medium => "200x200#" }
"""
When I successfully run `bundle exec rake paperclip
:
refresh
:
missing_styles
--trace`
Then
the attachment file
"original/5k.png"
should exist
And
the attachment file
"medium/5k.png"
should exist
@wip
Scenario
:
Paperclip clean task
When
I upload the fixture
"5k.png"
And
I upload the fixture
"12k.png"
Then
the attachment file
"original/5k.png"
should exist
And
the attachment file
"original/12k.png"
should exist
When I modify my attachment definition to
:
"""
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
validates_attachment_size :attachment, :less_than => 10.kilobytes
"""
And I successfully run `bundle exec rake paperclip
:
cle
an
CLASS=User --trace`
Then
the attachment file
"original/5k.png"
should exist
But
the attachment file
"original/12k.png"
should not exist
features/step_definitions/attachment_steps.rb
0 → 100644
View file @
898baf2c
module
AttachmentHelpers
def
fixture_path
(
filename
)
File
.
expand_path
(
"
#{
PROJECT_ROOT
}
/test/fixtures/
#{
filename
}
"
)
end
def
attachment_path
(
filename
)
File
.
expand_path
(
"public/system/attachments/
#{
filename
}
"
)
end
end
World
(
AttachmentHelpers
)
When
/^I modify my attachment definition to:$/
do
|
definition
|
in_current_dir
do
File
.
open
(
"app/models/user.rb"
,
"w"
)
do
|
file
|
file
.
write
<<-
FILE
class User < ActiveRecord::Base
#{
definition
}
end
FILE
end
end
end
When
/^I upload the fixture "([^"]*)"$/
do
|
filename
|
in_current_dir
do
run_simple
%(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))")
end
end
Then
/^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/
do
|
filename
,
dimension
|
in_current_dir
do
geometry
=
`identify -format "%wx%h" "
#{
attachment_path
(
filename
)
}
"`
.
strip
geometry
.
should
==
dimension
end
end
Then
/^the attachment "([^"]*)" should exist$/
do
|
filename
|
in_current_dir
do
File
.
exists?
(
attachment_path
(
filename
)).
should
be
end
end
When
/^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/
do
|
attachment_filename
,
fixture_filename
|
in_current_dir
do
require
'fileutils'
FileUtils
.
rm_f
attachment_path
(
attachment_filename
)
FileUtils
.
cp
fixture_path
(
fixture_filename
),
attachment_path
(
attachment_filename
)
end
end
Then
/^the attachment should have the same content type as the fixture "([^"]*)"$/
do
|
filename
|
in_current_dir
do
require
'mime/types'
attachment_content_type
=
`bundle exec rails runner "puts User.last.attachment_content_type"`
.
strip
attachment_content_type
.
should
==
MIME
::
Types
.
type_for
(
filename
).
first
.
content_type
end
end
Then
/^the attachment should have the same file size as the fixture "([^"]*)"$/
do
|
filename
|
in_current_dir
do
attachment_file_size
=
`bundle exec rails runner "puts User.last.attachment_file_size"`
.
strip
attachment_file_size
.
should
==
File
.
size
(
fixture_path
(
filename
)).
to_s
end
end
Then
/^the attachment file "([^"]*)" should (not )?exist$/
do
|
filename
,
not_exist
|
in_current_dir
do
check_file_presence
([
attachment_path
(
filename
)],
!
not_exist
)
end
end
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