From d1f21552939c07cf7f12b9674793bb14c81eb912 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Fri, 28 Dec 2012 01:46:36 +0100 Subject: work off FIXME comments in AR rename_column_test.rb There were a couple of tests, which had FIXME comments in palce of assertions. I replaced these FIXME comments with actual assertions to get more feedback from our test suite. --- .../test/cases/migration/rename_column_test.rb | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'activerecord/test/cases/migration/rename_column_test.rb') diff --git a/activerecord/test/cases/migration/rename_column_test.rb b/activerecord/test/cases/migration/rename_column_test.rb index 318d61263a..866b2e334c 100644 --- a/activerecord/test/cases/migration/rename_column_test.rb +++ b/activerecord/test/cases/migration/rename_column_test.rb @@ -84,16 +84,19 @@ module ActiveRecord add_column "test_models", :hat_name, :string add_index :test_models, :hat_name - # FIXME: we should test that the index goes away + assert_equal 1, connection.indexes('test_models').size rename_column "test_models", "hat_name", "name" + # FIXME: should we rename the index if it's name was autogenerated by rails? + assert_equal ['index_test_models_on_hat_name'], connection.indexes('test_models').map(&:name) end def test_remove_column_with_index add_column "test_models", :hat_name, :string add_index :test_models, :hat_name - # FIXME: we should test that the index goes away + assert_equal 1, connection.indexes('test_models').size remove_column("test_models", "hat_name") + assert_equal 0, connection.indexes('test_models').size end def test_remove_column_with_multi_column_index @@ -101,14 +104,24 @@ module ActiveRecord add_column "test_models", :hat_style, :string, :limit => 100 add_index "test_models", ["hat_style", "hat_size"], :unique => true - # FIXME: we should test that the index goes away + assert_equal 1, connection.indexes('test_models').size remove_column("test_models", "hat_size") + + # FIXME: should all adapters behave the same? + if current_adapter?(:PostgreSQLAdapter) + assert_equal [], connection.indexes('test_models').map(&:name) + else + assert_equal ['index_test_models_on_hat_style_and_hat_size'], connection.indexes('test_models').map(&:name) + end end - # FIXME: we need to test that these calls do something def test_change_type_of_not_null_column change_column "test_models", "updated_at", :datetime, :null => false change_column "test_models", "updated_at", :datetime, :null => false + + TestModel.reset_column_information + assert_equal false, TestModel.columns_hash['updated_at'].null + ensure change_column "test_models", "updated_at", :datetime, :null => true end @@ -119,7 +132,7 @@ module ActiveRecord change_column "test_models", "funny", :boolean, :null => false, :default => true TestModel.reset_column_information - refute TestModel.columns_hash["funny"].null, "Column 'funny' must *not* allow nulls at this point" + assert_not TestModel.columns_hash["funny"].null, "Column 'funny' must *not* allow nulls at this point" change_column "test_models", "funny", :boolean, :null => true TestModel.reset_column_information @@ -138,7 +151,7 @@ module ActiveRecord new_columns = connection.columns(TestModel.table_name) - refute new_columns.find { |c| c.name == 'age' and c.type == :integer } + assert_not new_columns.find { |c| c.name == 'age' and c.type == :integer } assert new_columns.find { |c| c.name == 'age' and c.type == :string } old_columns = connection.columns(TestModel.table_name) @@ -149,7 +162,7 @@ module ActiveRecord change_column :test_models, :approved, :boolean, :default => false new_columns = connection.columns(TestModel.table_name) - refute new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true } + assert_not new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true } assert new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == false } change_column :test_models, :approved, :boolean, :default => true end @@ -160,7 +173,7 @@ module ActiveRecord change_column "test_models", "contributor", :boolean, :default => nil TestModel.reset_column_information - refute TestModel.new.contributor? + assert_not TestModel.new.contributor? assert_nil TestModel.new.contributor end @@ -170,7 +183,7 @@ module ActiveRecord change_column "test_models", "administrator", :boolean, :default => false TestModel.reset_column_information - refute TestModel.new.administrator? + assert_not TestModel.new.administrator? end def test_change_column_with_custom_index_name -- cgit v1.2.3