Created
March 10, 2015 14:41
-
-
Save NikitaAvvakumov/ed794b55bf8d01b88650 to your computer and use it in GitHub Desktop.
Migration spec for adding father_deceased to Orphan and populating it with opposite values of existing father_alive column
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
#TODO Remove this brittle spec after it proves that the migration works | |
require 'rails_helper' | |
migration_file_name = '20150307173710_add_father_deceased_to_orphans.rb' | |
migration_file_path = Rails.root.join 'db', 'migrate', migration_file_name | |
version = migration_file_name.split('_').first | |
require migration_file_path | |
describe AddFatherDeceasedToOrphans do | |
let(:migration) { AddFatherDeceasedToOrphans.new } | |
before(:each) do | |
migration.down | |
end | |
describe '#up' do | |
before(:each) do | |
@father_alive_orphan = create :orphan, father_alive: true | |
@father_deceased_orphan = create :orphan, father_alive: false, | |
date_of_birth: 2.years.ago, father_date_of_death: 1.year.ago | |
migration.up | |
Orphan.reset_column_information | |
end | |
it 'sets father_deceased based on existing father_alive value' do | |
expect(@father_alive_orphan.reload.father_deceased).to eq false | |
expect(@father_deceased_orphan.reload.father_deceased).to eq true | |
end | |
end | |
def migration_has_been_run?(version) | |
query = "SELECT version FROM schema_migrations WHERE version = '#{version}'" | |
ActiveRecord::Base.connection.execute(query).any? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment