Support backwards compatible interface for migration down/up with rails 3.0.x.

This commit is contained in:
Christopher Meiklejohn
2011-07-29 21:26:21 -04:00
committed by Aaron Patterson
parent 3a4dc9d34c
commit 74d7bfb200
2 changed files with 25 additions and 0 deletions

View File

@@ -329,6 +329,7 @@ module ActiveRecord
end
def self.method_missing(name, *args, &block) # :nodoc:
self.delegate = self.new
(delegate || superclass.delegate).send(name, *args, &block)
end

View File

@@ -27,6 +27,19 @@ module ActiveRecord
end
end
class LegacyMigration < ActiveRecord::Migration
def self.up
create_table("horses") do |t|
t.column :content, :text
t.column :remind_at, :datetime
end
end
def self.down
drop_table("horses")
end
end
def teardown
if ActiveRecord::Base.connection.table_exists?("horses")
ActiveRecord::Base.connection.drop_table("horses")
@@ -53,5 +66,16 @@ module ActiveRecord
migration.migrate :down
assert !migration.connection.table_exists?("horses")
end
def test_legacy_up
LegacyMigration.migrate :up
assert ActiveRecord::Base.connection.table_exists?("horses"), "horses should exist"
end
def test_legacy_down
LegacyMigration.migrate :up
LegacyMigration.migrate :down
assert !ActiveRecord::Base.connection.table_exists?("horses"), "horses should not exist"
end
end
end