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
76cbfb80
Commit
76cbfb80
authored
Apr 23, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cucumber test for migrations
parent
90ea9dab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
1 deletions
+103
-1
features/migration.feature
+70
-0
features/step_definitions/attachment_steps.rb
+28
-0
features/step_definitions/rails_steps.rb
+5
-1
No files found.
features/migration.feature
0 → 100644
View file @
76cbfb80
Feature
:
Migration
Background
:
Given
I generate a new rails application
And I write to "app/models/user.rb" with
:
"""
class User < ActiveRecord::Base; end
"""
Scenario
:
Vintage syntax
When I write to "db/migrate/01_add_attachment_to_users.rb" with
:
"""
class AddAttachmentToUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.has_attached_file :avatar
end
end
def self.down
drop_attached_file :users, :avatar
end
end
"""
And
I run a migration
Then
I should have attachment columns for
"avatar"
When
I rollback a migration
Then
I should not have attachment columns for
"avatar"
Scenario
:
New syntax with create_table
When I write to "db/migrate/01_add_attachment_to_users.rb" with
:
"""
class AddAttachmentToUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.attachment :avatar
end
end
end
"""
And
I run a migration
Then
I should have attachment columns for
"avatar"
Scenario
:
New syntax outside of create_table
When I write to "db/migrate/01_create_users.rb" with
:
"""
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users
end
end
"""
And I write to "db/migrate/02_add_attachment_to_users.rb" with
:
"""
class AddAttachmentToUsers < ActiveRecord::Migration
def self.up
add_attachment :users, :avatar
end
def self.down
remove_attachment :users, :avatar
end
end
"""
And
I run a migration
Then
I should have attachment columns for
"avatar"
When
I rollback a migration
Then
I should not have attachment columns for
"avatar"
features/step_definitions/attachment_steps.rb
View file @
76cbfb80
...
...
@@ -72,3 +72,31 @@ Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exi
check_file_presence
([
attachment_path
(
filename
)],
!
not_exist
)
end
end
Then
/^I should have attachment columns for "([^"]*)"$/
do
|
attachment_name
|
in_current_dir
do
columns
=
eval
(
`bundle exec
#{
runner_command
}
"puts User.columns.map{ |column| [column.name, column.type] }.inspect"`
.
strip
)
expect_columns
=
[
[
"
#{
attachment_name
}
_file_name"
,
:string
],
[
"
#{
attachment_name
}
_content_type"
,
:string
],
[
"
#{
attachment_name
}
_file_size"
,
:integer
],
[
"
#{
attachment_name
}
_updated_at"
,
:datetime
]
]
expect_columns
.
all?
{
|
column
|
columns
.
include?
column
}.
should
be_true
end
end
Then
/^I should not have attachment columns for "([^"]*)"$/
do
|
attachment_name
|
in_current_dir
do
columns
=
eval
(
`bundle exec
#{
runner_command
}
"puts User.columns.map{ |column| [column.name, column.type] }.inspect"`
.
strip
)
expect_columns
=
[
[
"
#{
attachment_name
}
_file_name"
,
:string
],
[
"
#{
attachment_name
}
_content_type"
,
:string
],
[
"
#{
attachment_name
}
_file_size"
,
:integer
],
[
"
#{
attachment_name
}
_updated_at"
,
:datetime
]
]
expect_columns
.
none?
{
|
column
|
columns
.
include?
column
}.
should
be_true
end
end
features/step_definitions/rails_steps.rb
View file @
76cbfb80
...
...
@@ -29,7 +29,11 @@ Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)
end
Given
/^I run a migration$/
do
step
%[I successfully run `bundle exec rake db:migrate`]
step
%[I successfully run `bundle exec rake db:migrate --trace`]
end
When
/^I rollback a migration$/
do
step
%[I successfully run `bundle exec rake db:rollback STEPS=1 --trace`]
end
Given
/^I update my new user view to include the file upload field$/
do
...
...
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