Skip to content
This repository
Browse code

Support backwards compatible interface for migration down/up with rai…

…ls 3.0.x.
  • Loading branch information...
commit 74d7bfb200e4590e244558554e147a31d30990df 1 parent 3a4dc9d
Christopher Meiklejohn authored July 29, 2011 tenderlove committed August 02, 2011
1  activerecord/lib/active_record/migration.rb
@@ -329,6 +329,7 @@ class << self
329 329
     end
330 330
 
331 331
     def self.method_missing(name, *args, &block) # :nodoc:
  332
+      self.delegate = self.new
332 333
       (delegate || superclass.delegate).send(name, *args, &block)
333 334
     end
334 335
 
24  activerecord/test/cases/invertible_migration_test.rb
@@ -27,6 +27,19 @@ def change
27 27
       end
28 28
     end
29 29
 
  30
+    class LegacyMigration < ActiveRecord::Migration
  31
+      def self.up
  32
+        create_table("horses") do |t|
  33
+          t.column :content, :text
  34
+          t.column :remind_at, :datetime
  35
+        end
  36
+      end
  37
+
  38
+      def self.down
  39
+        drop_table("horses")
  40
+      end
  41
+    end
  42
+
30 43
     def teardown
31 44
       if ActiveRecord::Base.connection.table_exists?("horses")
32 45
         ActiveRecord::Base.connection.drop_table("horses")
@@ -53,5 +66,16 @@ def test_down
53 66
       migration.migrate :down
54 67
       assert !migration.connection.table_exists?("horses")
55 68
     end
  69
+
  70
+    def test_legacy_up
  71
+      LegacyMigration.migrate :up
  72
+      assert ActiveRecord::Base.connection.table_exists?("horses"), "horses should exist"
  73
+    end
  74
+
  75
+    def test_legacy_down
  76
+      LegacyMigration.migrate :up
  77
+      LegacyMigration.migrate :down
  78
+      assert !ActiveRecord::Base.connection.table_exists?("horses"), "horses should not exist"
  79
+    end
56 80
   end
57 81
 end

0 notes on commit 74d7bfb

Please sign in to comment.
Something went wrong with that request. Please try again.