rails--rails/activerecord/test/cases/invertible_migration_test.rb

58 lines
1.4 KiB
Ruby
Raw Normal View History

2010-11-18 23:52:13 +00:00
require "cases/helper"
module ActiveRecord
2010-11-19 18:55:57 +00:00
class InvertibleMigrationTest < ActiveRecord::TestCase
class SilentMigration < ActiveRecord::Migration
def write(text = '')
# sssshhhhh!!
end
end
2010-11-19 18:55:57 +00:00
class InvertibleMigration < SilentMigration
2010-11-18 23:52:13 +00:00
def change
create_table("horses") do |t|
t.column :content, :text
t.column :remind_at, :datetime
end
end
end
2010-11-18 23:52:13 +00:00
2010-11-19 18:55:57 +00:00
class NonInvertibleMigration < SilentMigration
def change
create_table("horses") do |t|
t.column :content, :text
t.column :remind_at, :datetime
end
remove_column "horses", :content
2010-11-18 23:52:13 +00:00
end
end
2010-11-19 19:42:58 +00:00
def teardown
2010-11-18 23:52:13 +00:00
if ActiveRecord::Base.connection.table_exists?("horses")
ActiveRecord::Base.connection.drop_table("horses")
end
end
def test_no_reverse
2010-11-19 18:55:57 +00:00
migration = NonInvertibleMigration.new
migration.migrate(:up)
assert_raises(IrreversibleMigration) do
migration.migrate(:down)
end
end
2010-11-18 23:52:13 +00:00
def test_up
2010-11-19 18:55:57 +00:00
migration = InvertibleMigration.new
2010-11-18 23:52:13 +00:00
migration.migrate(:up)
assert migration.connection.table_exists?("horses"), "horses should exist"
end
def test_down
2010-11-19 18:55:57 +00:00
migration = InvertibleMigration.new
2010-11-18 23:52:13 +00:00
migration.migrate :up
migration.migrate :down
assert !migration.connection.table_exists?("horses")
end
end
end