Skip to content

Instantly share code, notes, and snippets.

@pawlik
Created November 9, 2012 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlik/4048819 to your computer and use it in GitHub Desktop.
Save pawlik/4048819 to your computer and use it in GitHub Desktop.
fault spec migration test
# 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