Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NikitaAvvakumov/ed794b55bf8d01b88650 to your computer and use it in GitHub Desktop.
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
#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