diff options
author | Diego Algorta <diego@oboxodo.com> | 2008-06-21 20:18:30 -0300 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-22 15:21:11 -0700 |
commit | 2e1b56c93745bf0513e449e95830edd390abfaf2 (patch) | |
tree | 52ca66c284130235b34b8728d30ef5563fe7cbc5 /activerecord/test/cases | |
parent | a02d672cd7aead8a24e3b10a6b8e12dd91ee0a49 (diff) | |
download | rails-2e1b56c93745bf0513e449e95830edd390abfaf2.tar.gz rails-2e1b56c93745bf0513e449e95830edd390abfaf2.tar.bz2 rails-2e1b56c93745bf0513e449e95830edd390abfaf2.zip |
MySQL: rename_column preserves default values. [#466 state:resolved]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index f36255e209..2cac7f04ab 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -483,6 +483,32 @@ if ActiveRecord::Base.connection.supports_migrations? end end + def test_rename_column_preserves_default_value_not_null + begin + default_before = Developer.connection.columns("developers").find { |c| c.name == "salary" }.default + assert_equal 70000, default_before + Developer.connection.rename_column "developers", "salary", "anual_salary" + Developer.reset_column_information + assert Developer.column_names.include?("anual_salary") + default_after = Developer.connection.columns("developers").find { |c| c.name == "anual_salary" }.default + assert_equal 70000, default_after + ensure + Developer.connection.rename_column "developers", "anual_salary", "salary" + Developer.reset_column_information + end + end + + def test_rename_nonexistent_column + ActiveRecord::Base.connection.create_table(:hats) do |table| + table.column :hat_name, :string, :default => nil + end + assert_raises(ActiveRecord::ActiveRecordError) do + Person.connection.rename_column "hats", "nonexistent", "should_fail" + end + ensure + ActiveRecord::Base.connection.drop_table(:hats) + end + def test_rename_column_with_sql_reserved_word begin assert_nothing_raised { Person.connection.rename_column "people", "first_name", "group" } |