diff options
Diffstat (limited to 'activerecord/test/cases/migration')
7 files changed, 52 insertions, 37 deletions
diff --git a/activerecord/test/cases/migration/change_schema_test.rb b/activerecord/test/cases/migration/change_schema_test.rb index 86451289e7..5ac4a16f33 100644 --- a/activerecord/test/cases/migration/change_schema_test.rb +++ b/activerecord/test/cases/migration/change_schema_test.rb @@ -50,7 +50,7 @@ module ActiveRecord def test_create_table_with_defaults # MySQL doesn't allow defaults on TEXT or BLOB columns. - mysql = current_adapter?(:MysqlAdapter) || current_adapter?(:Mysql2Adapter) + mysql = current_adapter?(:MysqlAdapter, :Mysql2Adapter) connection.create_table :testings do |t| t.column :one, :string, :default => "hello" @@ -99,7 +99,7 @@ module ActiveRecord assert_equal 'smallint', one.sql_type assert_equal 'integer', four.sql_type assert_equal 'bigint', eight.sql_type - elsif current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter) + elsif current_adapter?(:MysqlAdapter, :Mysql2Adapter) assert_match 'int(11)', default.sql_type assert_match 'tinyint', one.sql_type assert_match 'int', four.sql_type @@ -293,7 +293,7 @@ module ActiveRecord end assert connection.column_exists?(:testings, :foo) - refute connection.column_exists?(:testings, :bar) + assert_not connection.column_exists?(:testings, :bar) end def test_column_exists_with_type @@ -303,10 +303,10 @@ module ActiveRecord end assert connection.column_exists?(:testings, :foo, :string) - refute connection.column_exists?(:testings, :foo, :integer) + assert_not connection.column_exists?(:testings, :foo, :integer) assert connection.column_exists?(:testings, :bar, :decimal) - refute connection.column_exists?(:testings, :bar, :integer) + assert_not connection.column_exists?(:testings, :bar, :integer) end def test_column_exists_with_definition @@ -318,13 +318,13 @@ module ActiveRecord end assert connection.column_exists?(:testings, :foo, :string, limit: 100) - refute connection.column_exists?(:testings, :foo, :string, limit: nil) + assert_not connection.column_exists?(:testings, :foo, :string, limit: nil) assert connection.column_exists?(:testings, :bar, :decimal, precision: 8, scale: 2) - refute connection.column_exists?(:testings, :bar, :decimal, precision: nil, scale: nil) + assert_not connection.column_exists?(:testings, :bar, :decimal, precision: nil, scale: nil) assert connection.column_exists?(:testings, :taggable_id, :integer, null: false) - refute connection.column_exists?(:testings, :taggable_id, :integer, null: true) + assert_not connection.column_exists?(:testings, :taggable_id, :integer, null: true) assert connection.column_exists?(:testings, :taggable_type, :string, default: 'Photo') - refute connection.column_exists?(:testings, :taggable_type, :string, default: nil) + assert_not connection.column_exists?(:testings, :taggable_type, :string, default: nil) end def test_column_exists_on_table_with_no_options_parameter_supplied diff --git a/activerecord/test/cases/migration/change_table_test.rb b/activerecord/test/cases/migration/change_table_test.rb index ac1ad176db..8065541bfe 100644 --- a/activerecord/test/cases/migration/change_table_test.rb +++ b/activerecord/test/cases/migration/change_table_test.rb @@ -1,4 +1,5 @@ require "cases/migration/helper" +require "minitest/mock" module ActiveRecord class Migration diff --git a/activerecord/test/cases/migration/column_attributes_test.rb b/activerecord/test/cases/migration/column_attributes_test.rb index b88db384a0..ec2926632c 100644 --- a/activerecord/test/cases/migration/column_attributes_test.rb +++ b/activerecord/test/cases/migration/column_attributes_test.rb @@ -16,7 +16,7 @@ module ActiveRecord end def test_add_remove_single_field_using_string_arguments - refute TestModel.column_methods_hash.key?(:last_name) + assert_not TestModel.column_methods_hash.key?(:last_name) add_column 'test_models', 'last_name', :string @@ -27,11 +27,11 @@ module ActiveRecord remove_column 'test_models', 'last_name' TestModel.reset_column_information - refute TestModel.column_methods_hash.key?(:last_name) + assert_not TestModel.column_methods_hash.key?(:last_name) end def test_add_remove_single_field_using_symbol_arguments - refute TestModel.column_methods_hash.key?(:last_name) + assert_not TestModel.column_methods_hash.key?(:last_name) add_column :test_models, :last_name, :string @@ -41,7 +41,7 @@ module ActiveRecord remove_column :test_models, :last_name TestModel.reset_column_information - refute TestModel.column_methods_hash.key?(:last_name) + assert_not TestModel.column_methods_hash.key?(:last_name) end def test_unabstracted_database_dependent_types diff --git a/activerecord/test/cases/migration/index_test.rb b/activerecord/test/cases/migration/index_test.rb index 0787414d8f..a41f2c10f0 100644 --- a/activerecord/test/cases/migration/index_test.rb +++ b/activerecord/test/cases/migration/index_test.rb @@ -35,7 +35,7 @@ module ActiveRecord connection.rename_index(table_name, 'old_idx', 'new_idx') # if the adapter doesn't support the indexes call, pick defaults that let the test pass - refute connection.index_name_exists?(table_name, 'old_idx', false) + assert_not connection.index_name_exists?(table_name, 'old_idx', false) assert connection.index_name_exists?(table_name, 'new_idx', true) end @@ -63,7 +63,7 @@ module ActiveRecord connection.add_index(table_name, "foo", :name => too_long_index_name) } - refute connection.index_name_exists?(table_name, too_long_index_name, false) + assert_not connection.index_name_exists?(table_name, too_long_index_name, false) connection.add_index(table_name, "foo", :name => good_index_name) assert connection.index_name_exists?(table_name, good_index_name, false) @@ -75,7 +75,7 @@ module ActiveRecord assert connection.index_exists?(table_name, :foo, :name => :symbol_index_name) connection.remove_index table_name, :name => :symbol_index_name - refute connection.index_exists?(table_name, :foo, :name => :symbol_index_name) + assert_not connection.index_exists?(table_name, :foo, :name => :symbol_index_name) end def test_index_exists diff --git a/activerecord/test/cases/migration/references_index_test.rb b/activerecord/test/cases/migration/references_index_test.rb index 264a99f9ce..3ff89524fe 100644 --- a/activerecord/test/cases/migration/references_index_test.rb +++ b/activerecord/test/cases/migration/references_index_test.rb @@ -29,7 +29,7 @@ module ActiveRecord t.references :foo end - refute connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id) + assert_not connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id) end def test_does_not_create_index_explicit @@ -37,7 +37,7 @@ module ActiveRecord t.references :foo, :index => false end - refute connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id) + assert_not connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id) end def test_creates_index_with_options @@ -75,7 +75,7 @@ module ActiveRecord t.references :foo end - refute connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id) + assert_not connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id) end def test_does_not_create_index_for_existing_table_explicit @@ -84,7 +84,7 @@ module ActiveRecord t.references :foo, :index => false end - refute connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id) + assert_not connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_foo_id) end def test_creates_polymorphic_index_for_existing_table diff --git a/activerecord/test/cases/migration/references_statements_test.rb b/activerecord/test/cases/migration/references_statements_test.rb index d8a6565d54..e9545f2cce 100644 --- a/activerecord/test/cases/migration/references_statements_test.rb +++ b/activerecord/test/cases/migration/references_statements_test.rb @@ -22,7 +22,7 @@ module ActiveRecord def test_does_not_create_reference_type_column add_reference table_name, :taggable - refute column_exists?(table_name, :taggable_type, :string) + assert_not column_exists?(table_name, :taggable_type, :string) end def test_creates_reference_type_column @@ -37,7 +37,7 @@ module ActiveRecord def test_does_not_create_reference_id_index add_reference table_name, :user - refute index_exists?(table_name, :user_id) + assert_not index_exists?(table_name, :user_id) end def test_creates_polymorphic_index @@ -57,19 +57,19 @@ module ActiveRecord def test_deletes_reference_id_column remove_reference table_name, :supplier - refute column_exists?(table_name, :supplier_id, :integer) + assert_not column_exists?(table_name, :supplier_id, :integer) end def test_deletes_reference_id_index remove_reference table_name, :supplier - refute index_exists?(table_name, :supplier_id) + assert_not index_exists?(table_name, :supplier_id) end def test_does_not_delete_reference_type_column with_polymorphic_column do remove_reference table_name, :supplier - refute column_exists?(table_name, :supplier_id, :integer) + assert_not column_exists?(table_name, :supplier_id, :integer) assert column_exists?(table_name, :supplier_type, :string) end end @@ -77,14 +77,14 @@ module ActiveRecord def test_deletes_reference_type_column with_polymorphic_column do remove_reference table_name, :supplier, polymorphic: true - refute column_exists?(table_name, :supplier_type, :string) + assert_not column_exists?(table_name, :supplier_type, :string) end end def test_deletes_polymorphic_index with_polymorphic_column do remove_reference table_name, :supplier, polymorphic: true - refute index_exists?(table_name, [:supplier_id, :supplier_type]) + assert_not index_exists?(table_name, [:supplier_id, :supplier_type]) end end @@ -95,7 +95,7 @@ module ActiveRecord def test_remove_belongs_to_alias remove_belongs_to table_name, :supplier - refute column_exists?(table_name, :supplier_id, :integer) + assert_not column_exists?(table_name, :supplier_id, :integer) end private diff --git a/activerecord/test/cases/migration/rename_column_test.rb b/activerecord/test/cases/migration/rename_column_test.rb index 318d61263a..8f6918d06a 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,25 @@ 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") + + # Every database and/or database adapter has their own behavior + # if it drops the multi-column index when any of the indexed columns dropped by remove_column. + if current_adapter?(:PostgreSQLAdapter, :OracleAdapter) + 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 +133,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 +152,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 +163,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 +174,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 +184,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 |