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
03700c86
Commit
03700c86
authored
Apr 09, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for generator
parent
a2a4c7a1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
1 deletions
+78
-1
lib/generators/paperclip/paperclip_generator.rb
+0
-1
test/generator_test.rb
+78
-0
No files found.
lib/generators/paperclip/paperclip_generator.rb
View file @
03700c86
...
...
@@ -29,5 +29,4 @@ class PaperclipGenerator < ActiveRecord::Generators::Base
def
migration_class_name
migration_name
.
camelize
end
end
test/generator_test.rb
0 → 100644
View file @
03700c86
require
'./test/helper'
require
'rails/generators'
require
'generators/paperclip/paperclip_generator'
class
GeneratorTest
<
Rails
::
Generators
::
TestCase
tests
PaperclipGenerator
destination
File
.
expand_path
(
"../tmp"
,
File
.
dirname
(
__FILE__
))
setup
:prepare_destination
context
'running migration'
do
context
'with single attachment name'
do
setup
do
run_generator
%w(user avatar)
end
should
'create a correct migration file'
do
assert_migration
'db/migrate/add_attachment_avatar_to_user.rb'
do
|
migration
|
assert_match
/class AddAttachmentAvatarToUser/
,
migration
assert_class_method
:up
,
migration
do
|
up
|
assert_match
/add_column :users, :avatar_file_name, :string/
,
up
assert_match
/add_column :users, :avatar_content_type, :string/
,
up
assert_match
/add_column :users, :avatar_file_size, :integer/
,
up
assert_match
/add_column :users, :avatar_updated_at, :datetime/
,
up
end
assert_class_method
:down
,
migration
do
|
down
|
assert_match
/remove_column :users, :avatar_file_name/
,
down
assert_match
/remove_column :users, :avatar_content_type/
,
down
assert_match
/remove_column :users, :avatar_file_size/
,
down
assert_match
/remove_column :users, :avatar_updated_at/
,
down
end
end
end
end
context
'with multiple attachment names'
do
setup
do
run_generator
%w(user avatar photo)
end
should
'create a correct migration file'
do
assert_migration
'db/migrate/add_attachment_avatar_photo_to_user.rb'
do
|
migration
|
assert_match
/class AddAttachmentAvatarPhotoToUser/
,
migration
assert_class_method
:up
,
migration
do
|
up
|
assert_match
/add_column :users, :avatar_file_name, :string/
,
up
assert_match
/add_column :users, :avatar_content_type, :string/
,
up
assert_match
/add_column :users, :avatar_file_size, :integer/
,
up
assert_match
/add_column :users, :avatar_updated_at, :datetime/
,
up
assert_match
/add_column :users, :photo_file_name, :string/
,
up
assert_match
/add_column :users, :photo_content_type, :string/
,
up
assert_match
/add_column :users, :photo_file_size, :integer/
,
up
assert_match
/add_column :users, :photo_updated_at, :datetime/
,
up
end
assert_class_method
:down
,
migration
do
|
down
|
assert_match
/remove_column :users, :avatar_file_name/
,
down
assert_match
/remove_column :users, :avatar_content_type/
,
down
assert_match
/remove_column :users, :avatar_file_size/
,
down
assert_match
/remove_column :users, :avatar_updated_at/
,
down
assert_match
/remove_column :users, :photo_file_name/
,
down
assert_match
/remove_column :users, :photo_content_type/
,
down
assert_match
/remove_column :users, :photo_file_size/
,
down
assert_match
/remove_column :users, :photo_updated_at/
,
down
end
end
end
end
context
'without required arguments'
do
should
'not create the migration'
do
silence_stream
(
STDERR
)
{
run_generator
%w()
}
assert_no_migration
'db/migrate/add_attachment_avatar_to_user.rb'
end
end
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