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
def
self
.
up
change_table
:
<%=
table_name
%>
do
|
t
|
<%
attachment_names
.
each
do
|
attachment
|
-%>
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
,
:string
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
t
.
has_attached_file
:
<%=
attachment
%>
<%
end
-%>
end
end
def
self
.
down
<%
attachment_names
.
each
do
|
attachment
|
-%>
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
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
drop_attached_file
:
<%=
table_name
%>
,
:
<%=
attachment
%>
<%
end
-%>
end
end
test/generator_test.rb
View file @
ef646f3b
...
...
@@ -18,17 +18,21 @@ class GeneratorTest < Rails::Generators::TestCase
assert_match
/class AddAttachmentAvatarToUsers/
,
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
expected
=
<<-
migration
change_table :users do |t|
t.has_attached_file :avatar
end
migration
assert_equal
expected
.
squish
,
up
.
squish
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
expected
=
<<-
migration
drop_attached_file :users, :avatar
migration
assert_equal
expected
.
squish
,
down
.
squish
end
end
end
...
...
@@ -44,25 +48,23 @@ class GeneratorTest < Rails::Generators::TestCase
assert_match
/class AddAttachmentAvatarPhotoToUsers/
,
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
expected
=
<<-
migration
change_table :users do |t|
t.has_attached_file :avatar
t.has_attached_file :photo
end
migration
assert_
equal
expected
.
squish
,
up
.
squish
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
expected
=
<<-
migration
drop_attached_file :users, :avatar
drop_attached_file :users, :photo
migration
assert_equal
expected
.
squish
,
down
.
squish
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