aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/migration_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/migration_test.rb')
-rw-r--r--activerecord/test/migration_test.rb63
1 files changed, 54 insertions, 9 deletions
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index 72d0fbf817..a266afed2f 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/fixtures/migrations/1_people_have_last_names'
require File.dirname(__FILE__) + '/fixtures/migrations/2_we_need_reminders'
if ActiveRecord::Base.connection.supports_migrations?
+
class Reminder < ActiveRecord::Base; end
class MigrationTest < Test::Unit::TestCase
@@ -15,6 +16,7 @@ if ActiveRecord::Base.connection.supports_migrations?
ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
Reminder.connection.drop_table("reminders") rescue nil
+ Reminder.connection.drop_table("people_reminders") rescue nil
Reminder.reset_column_information
Person.connection.remove_column("people", "last_name") rescue nil
@@ -24,11 +26,21 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.connection.remove_column("people", "birthday") rescue nil
Person.connection.remove_column("people", "favorite_day") rescue nil
Person.connection.remove_column("people", "male") rescue nil
+ Person.connection.remove_column("people", "administrator") rescue nil
Person.reset_column_information
end
+
+ def test_add_index
+ Person.connection.add_column "people", "last_name", :string
+
+ assert_nothing_raised { Person.connection.add_index("people", "last_name") }
+ assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
+
+ assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
+ assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
+ end
def test_native_types
-
Person.delete_all
Person.connection.add_column "people", "last_name", :string
Person.connection.add_column "people", "bio", :text
@@ -62,21 +74,54 @@ if ActiveRecord::Base.connection.supports_migrations?
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
-
+
PeopleHaveLastNames.down
Person.reset_column_information
assert !Person.column_methods_hash.include?(:last_name)
end
+
+ def test_add_rename
+ Person.delete_all
+
+ Person.connection.add_column "people", "girlfriend", :string
+ Person.create :girlfriend => 'bobette'
+
+ begin
+ Person.connection.rename_column "people", "girlfriend", "exgirlfriend"
+
+ Person.reset_column_information
+ bob = Person.find(:first)
+
+ assert_equal "bobette", bob.exgirlfriend
+ ensure
+ Person.connection.remove_column("people", "girlfriend") rescue nil
+ Person.connection.remove_column("people", "exgirlfriend") rescue nil
+ end
+
+ end
+
+ def test_change_column
+ Person.connection.add_column "people", "bio", :string
+ assert_nothing_raised { Person.connection.change_column "people", "bio", :text }
+ end
+
+ def test_change_column_with_new_default
+ Person.connection.add_column "people", "administrator", :boolean, :default => 1
+ assert Person.new.administrator?
+
+ assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => 0 }
+ assert !Person.new.administrator?
+ end
def test_add_table
assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash }
-
+
WeNeedReminders.up
-
+
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
assert_equal "hello world", Reminder.find(:first).content
-
+
WeNeedReminders.down
assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
end
@@ -87,7 +132,7 @@ if ActiveRecord::Base.connection.supports_migrations?
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
- assert_equal 2, ActiveRecord::Migrator.current_version
+ assert_equal 3, ActiveRecord::Migrator.current_version
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
@@ -117,17 +162,17 @@ if ActiveRecord::Base.connection.supports_migrations?
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
assert_equal "hello world", Reminder.find(:first).content
end
-
+
def test_migrator_one_down
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/')
-
+
ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash }
end
-
+
def test_migrator_one_up_one_down
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 0)