Created
November 9, 2012 22:45
-
-
Save g-pavlik/4048819 to your computer and use it in GitHub Desktop.
fault spec migration test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file extract_addresses_from_companies | |
load 'spec/spec_helper.rb' | |
load 'db/migrate/20121109212148_extract_addresses_from_companies.rb' | |
describe ExtractAddressesFromCompanies do | |
before do | |
@previous_migration_version = '20121108165838' | |
@my_migration_version = '20121109212148' | |
end | |
describe ".up" do | |
before do | |
ActiveRecord::Migrator.migrate @previous_migration_version | |
end | |
it "adds address_id column to the companies table" do | |
expect { | |
ExtractAddressesFromCompanies.up | |
Company.reset_column_information | |
}.to change{Company.columns.map(&:name)} | |
Company.columns.map(&:name).should include("address_id") | |
end | |
end | |
describe ".down" do | |
before do | |
ActiveRecord::Migrator.migrate @my_migration_version | |
end | |
it "removes 'address_id' column from companies table" do | |
expect { | |
ExtractAddressesFromCompanies.down | |
Company.reset_column_information | |
}.to change {Company.columns.map(&:name)} | |
Company.columns.map(&:name).should_not include("address_id") | |
end | |
end | |
end | |
# 20121109212148_extract_addresses_from_companies.rb | |
class ExtractAddressesFromCompanies < ActiveRecord::Migration | |
def up | |
add_column :companies, :address_id, :integer | |
end | |
def down | |
remove_column :companies, :address_id | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment