Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created March 8, 2009 17:37
Show Gist options
  • Save bkeepers/75839 to your computer and use it in GitHub Desktop.
Save bkeepers/75839 to your computer and use it in GitHub Desktop.
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
#
# This excercises the full set of migrations for your Rails app.
# It proves:
# - After full migration, the database is in the expected state, including:
# - All table structure
# - Default data (if any)
# - Full downward (version 0) migration functions correctly.
#
# YOU NEED TO:
# - Update "see_full_schema"
# - Update "see_data"
#
class FullMigrationTest < ActionController::IntegrationTest
#
# Transactional fixtures can, on occasion, cause migration tests to hang.
# Applying this setting here will turn transactional fixtures off for THIS
# SUITE ONLY
#
# self.use_transactional_fixtures = false
def conn
ActiveRecord::Base.connection
end
def see_empty_schema
assert_schema do |s|
# is nothing
end
end
#
# Structure and Content assertions
#
# Fully assert db structure after full migration
def see_full_schema
assert_schema do |s|
s.table "appointments" do |t|
t.datetime "begin_at"
t.text "location"
t.text "description"
t.integer "lead_id"
t.integer "job_id"
t.integer "contact_id"
t.integer "lock_version"
t.datetime "created_at"
t.datetime "updated_at"
end
# …
end
end
# Make sure data you expect your migrations to load are in there:
def see_default_data
# TODO: add assertions here to verify any default data was loaded
end
#
# TESTS
#
def test_full_migration
drop_all_tables
see_empty_schema
migrate
see_full_schema
see_default_data
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment