Commit 76cbfb80 by Prem Sichanugrist

Add cucumber test for migrations

parent 90ea9dab
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"
......@@ -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
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment