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
ef646f3b
Commit
ef646f3b
authored
Apr 12, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Paperclip sexy migration in the generator
parent
b09bb31b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
32 deletions
+30
-32
lib/generators/paperclip/templates/paperclip_migration.rb.erb
+4
-8
test/generator_test.rb
+26
-24
No files found.
lib/generators/paperclip/templates/paperclip_migration.rb.erb
View file @
ef646f3b
class
<%=
migration_class_name
%>
<
ActiveRecord::Migration
class
<%=
migration_class_name
%>
<
ActiveRecord::Migration
def
self
.
up
def
self
.
up
change_table
:
<%=
table_name
%>
do
|
t
|
<%
attachment_names
.
each
do
|
attachment
|
-%>
<%
attachment_names
.
each
do
|
attachment
|
-%>
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
,
:string
t
.
has_attached_file
:
<%=
attachment
%>
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_content_type
,
:string
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_size
,
:integer
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_updated_at
,
:datetime
<%
end
-%>
<%
end
-%>
end
end
end
def
self
.
down
def
self
.
down
<%
attachment_names
.
each
do
|
attachment
|
-%>
<%
attachment_names
.
each
do
|
attachment
|
-%>
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
drop_attached_file
:
<%=
table_name
%>
,
:
<%=
attachment
%>
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_content_type
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_size
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_updated_at
<%
end
-%>
<%
end
-%>
end
end
end
end
test/generator_test.rb
View file @
ef646f3b
...
@@ -18,17 +18,21 @@ class GeneratorTest < Rails::Generators::TestCase
...
@@ -18,17 +18,21 @@ class GeneratorTest < Rails::Generators::TestCase
assert_match
/class AddAttachmentAvatarToUsers/
,
migration
assert_match
/class AddAttachmentAvatarToUsers/
,
migration
assert_class_method
:up
,
migration
do
|
up
|
assert_class_method
:up
,
migration
do
|
up
|
assert_match
/add_column :users, :avatar_file_name, :string/
,
up
expected
=
<<-
migration
assert_match
/add_column :users, :avatar_content_type, :string/
,
up
change_table :users do |t|
assert_match
/add_column :users, :avatar_file_size, :integer/
,
up
t.has_attached_file :avatar
assert_match
/add_column :users, :avatar_updated_at, :datetime/
,
up
end
migration
assert_equal
expected
.
squish
,
up
.
squish
end
end
assert_class_method
:down
,
migration
do
|
down
|
assert_class_method
:down
,
migration
do
|
down
|
assert_match
/remove_column :users, :avatar_file_name/
,
down
expected
=
<<-
migration
assert_match
/remove_column :users, :avatar_content_type/
,
down
drop_attached_file :users, :avatar
assert_match
/remove_column :users, :avatar_file_size/
,
down
migration
assert_match
/remove_column :users, :avatar_updated_at/
,
down
assert_equal
expected
.
squish
,
down
.
squish
end
end
end
end
end
end
...
@@ -44,25 +48,23 @@ class GeneratorTest < Rails::Generators::TestCase
...
@@ -44,25 +48,23 @@ class GeneratorTest < Rails::Generators::TestCase
assert_match
/class AddAttachmentAvatarPhotoToUsers/
,
migration
assert_match
/class AddAttachmentAvatarPhotoToUsers/
,
migration
assert_class_method
:up
,
migration
do
|
up
|
assert_class_method
:up
,
migration
do
|
up
|
assert_match
/add_column :users, :avatar_file_name, :string/
,
up
expected
=
<<-
migration
assert_match
/add_column :users, :avatar_content_type, :string/
,
up
change_table :users do |t|
assert_match
/add_column :users, :avatar_file_size, :integer/
,
up
t.has_attached_file :avatar
assert_match
/add_column :users, :avatar_updated_at, :datetime/
,
up
t.has_attached_file :photo
assert_match
/add_column :users, :photo_file_name, :string/
,
up
end
assert_match
/add_column :users, :photo_content_type, :string/
,
up
migration
assert_match
/add_column :users, :photo_file_size, :integer/
,
up
assert_
match
/add_column :users, :photo_updated_at, :datetime/
,
up
assert_
equal
expected
.
squish
,
up
.
squish
end
end
assert_class_method
:down
,
migration
do
|
down
|
assert_class_method
:down
,
migration
do
|
down
|
assert_match
/remove_column :users, :avatar_file_name/
,
down
expected
=
<<-
migration
assert_match
/remove_column :users, :avatar_content_type/
,
down
drop_attached_file :users, :avatar
assert_match
/remove_column :users, :avatar_file_size/
,
down
drop_attached_file :users, :photo
assert_match
/remove_column :users, :avatar_updated_at/
,
down
migration
assert_match
/remove_column :users, :photo_file_name/
,
down
assert_match
/remove_column :users, :photo_content_type/
,
down
assert_equal
expected
.
squish
,
down
.
squish
assert_match
/remove_column :users, :photo_file_size/
,
down
assert_match
/remove_column :users, :photo_updated_at/
,
down
end
end
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