diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-05 07:19:20 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-05 07:19:20 +0000 |
commit | f1880cac5862172608ff26d1178a31c05b904d77 (patch) | |
tree | aab6bdf693ab0f7495e308a9813432938d95e040 /activerecord/test | |
parent | 2418a68aa23c96ce20aae6168c71c760cb6e7809 (diff) | |
download | rails-f1880cac5862172608ff26d1178a31c05b904d77.tar.gz rails-f1880cac5862172608ff26d1178a31c05b904d77.tar.bz2 rails-f1880cac5862172608ff26d1178a31c05b904d77.zip |
Sugared up migrations with even more bling #1609 [Tobias Luekte]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1697 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/fixtures/migrations/3_innocent_jointable.rb | 12 | ||||
-rw-r--r-- | activerecord/test/migration_test.rb | 63 |
2 files changed, 66 insertions, 9 deletions
diff --git a/activerecord/test/fixtures/migrations/3_innocent_jointable.rb b/activerecord/test/fixtures/migrations/3_innocent_jointable.rb new file mode 100644 index 0000000000..21c9ca5328 --- /dev/null +++ b/activerecord/test/fixtures/migrations/3_innocent_jointable.rb @@ -0,0 +1,12 @@ +class InnocentJointable < ActiveRecord::Migration + def self.up + create_table("people_reminders", :id => false) do |t| + t.column :reminder_id, :integer + t.column :person_id, :integer + end + end + + def self.down + drop_table "people_reminders" + end +end
\ No newline at end of file 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) |