diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-11 17:14:44 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-13 14:33:55 -0800 |
commit | a39498544793878dcf4eb02a32e59d4c6ee1c9a3 (patch) | |
tree | b77262ef088a7ba3eed42bcaaeca7cc0ca4c5d44 /activerecord/test/cases | |
parent | 5c8da16a20d43171fd17ebcdca7a57ec7761859e (diff) | |
download | rails-a39498544793878dcf4eb02a32e59d4c6ee1c9a3.tar.gz rails-a39498544793878dcf4eb02a32e59d4c6ee1c9a3.tar.bz2 rails-a39498544793878dcf4eb02a32e59d4c6ee1c9a3.zip |
move tests regarding index modification to their own class
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/migration/change_schema_test.rb | 84 | ||||
-rw-r--r-- | activerecord/test/cases/migration/index_test.rb | 102 | ||||
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 18 |
3 files changed, 102 insertions, 102 deletions
diff --git a/activerecord/test/cases/migration/change_schema_test.rb b/activerecord/test/cases/migration/change_schema_test.rb index 8d4c1272a4..72c5892d4f 100644 --- a/activerecord/test/cases/migration/change_schema_test.rb +++ b/activerecord/test/cases/migration/change_schema_test.rb @@ -17,90 +17,6 @@ module ActiveRecord ActiveRecord::Base.primary_key_prefix_type = nil end - def test_remove_nonexistent_index - skip "not supported on openbase" if current_adapter?(:OpenBaseAdapter) - - connection.create_table table_name do |t| - t.column :foo, :string, :limit => 100 - t.column :bar, :string, :limit => 100 - end - - # we do this by name, so OpenBase is a wash as noted above - assert_raise(ArgumentError) { connection.remove_index(table_name, "no_such_index") } - end - - def test_add_index_length_limit - connection.create_table table_name do |t| - t.column :foo, :string, :limit => 100 - t.column :bar, :string, :limit => 100 - end - - good_index_name = 'x' * connection.index_name_length - too_long_index_name = good_index_name + 'x' - - assert_raises(ArgumentError) { - connection.add_index(table_name, "foo", :name => too_long_index_name) - } - - refute 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) - connection.remove_index(table_name, :name => good_index_name) - end - - def test_index_symbol_names - connection.create_table :testings do |t| - t.column :foo, :string, :limit => 100 - t.column :bar, :string, :limit => 100 - end - - connection.add_index table_name, :foo, :name => :symbol_index_name - 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) - end - - def test_index_exists - connection.create_table :testings do |t| - t.column :foo, :string, :limit => 100 - t.column :bar, :string, :limit => 100 - end - connection.add_index :testings, :foo - - assert connection.index_exists?(:testings, :foo) - assert !connection.index_exists?(:testings, :bar) - end - - def test_index_exists_on_multiple_columns - connection.create_table :testings do |t| - t.column :foo, :string, :limit => 100 - t.column :bar, :string, :limit => 100 - end - connection.add_index :testings, [:foo, :bar] - - assert connection.index_exists?(:testings, [:foo, :bar]) - end - - def test_unique_index_exists - connection.create_table :testings do |t| - t.column :foo, :string, :limit => 100 - end - connection.add_index :testings, :foo, :unique => true - - assert connection.index_exists?(:testings, :foo, :unique => true) - end - - def test_named_index_exists - connection.create_table :testings do |t| - t.column :foo, :string, :limit => 100 - end - connection.add_index :testings, :foo, :name => "custom_index_name" - - assert connection.index_exists?(:testings, :foo, :name => "custom_index_name") - end - def test_create_table_without_id testing_table_with_only_foo_attribute do assert_equal connection.columns(:testings).size, 1 diff --git a/activerecord/test/cases/migration/index_test.rb b/activerecord/test/cases/migration/index_test.rb new file mode 100644 index 0000000000..a79a20aa1a --- /dev/null +++ b/activerecord/test/cases/migration/index_test.rb @@ -0,0 +1,102 @@ +require 'cases/helper' + +module ActiveRecord + class Migration + class IndexTest < ActiveRecord::TestCase + attr_reader :connection, :table_name + + def setup + super + @connection = ActiveRecord::Base.connection + @table_name = :testings + + connection.create_table table_name do |t| + t.column :foo, :string, :limit => 100 + t.column :bar, :string, :limit => 100 + end + end + + def teardown + super + connection.drop_table :testings rescue nil + ActiveRecord::Base.primary_key_prefix_type = nil + end + + def test_rename_index + skip "not supported on openbase" if current_adapter?(:OpenBaseAdapter) + + # keep the names short to make Oracle and similar behave + connection.add_index(table_name, [:foo], :name => 'old_idx') + 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 connection.index_name_exists?(table_name, 'new_idx', true) + end + + def test_double_add_index + skip "not supported on openbase" if current_adapter?(:OpenBaseAdapter) + + connection.add_index(table_name, [:foo], :name => 'some_idx') + assert_raises(ArgumentError) { + connection.add_index(table_name, [:foo], :name => 'some_idx') + } + end + + def test_remove_nonexistent_index + skip "not supported on openbase" if current_adapter?(:OpenBaseAdapter) + + # we do this by name, so OpenBase is a wash as noted above + assert_raise(ArgumentError) { connection.remove_index(table_name, "no_such_index") } + end + + def test_add_index_length_limit + good_index_name = 'x' * connection.index_name_length + too_long_index_name = good_index_name + 'x' + + assert_raises(ArgumentError) { + connection.add_index(table_name, "foo", :name => too_long_index_name) + } + + refute 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) + connection.remove_index(table_name, :name => good_index_name) + end + + def test_index_symbol_names + connection.add_index table_name, :foo, :name => :symbol_index_name + 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) + end + + def test_index_exists + connection.add_index :testings, :foo + + assert connection.index_exists?(:testings, :foo) + assert !connection.index_exists?(:testings, :bar) + end + + def test_index_exists_on_multiple_columns + connection.add_index :testings, [:foo, :bar] + + assert connection.index_exists?(:testings, [:foo, :bar]) + end + + def test_unique_index_exists + connection.add_index :testings, :foo, :unique => true + + assert connection.index_exists?(:testings, :foo, :unique => true) + end + + def test_named_index_exists + connection.add_index :testings, :foo, :name => "custom_index_name" + + assert connection.index_exists?(:testings, :foo, :name => "custom_index_name") + end + end + end +end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 0519826ae0..207a9aeacd 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -62,24 +62,6 @@ class MigrationTest < ActiveRecord::TestCase Person.reset_column_information end - def test_rename_index - skip "not supported on openbase" if current_adapter?(:OpenBaseAdapter) - - # keep the names short to make Oracle and similar behave - Person.connection.add_index('people', [:first_name], :name => 'old_idx') - assert_nothing_raised { Person.connection.rename_index('people', 'old_idx', 'new_idx') } - # if the adapter doesn't support the indexes call, pick defaults that let the test pass - assert !Person.connection.index_name_exists?('people', 'old_idx', false) - assert Person.connection.index_name_exists?('people', 'new_idx', true) - end - - def test_double_add_index - skip "not supported on openbase" if current_adapter?(:OpenBaseAdapter) - - Person.connection.add_index('people', [:first_name], :name => 'some_idx') - assert_raise(ArgumentError) { Person.connection.add_index('people', [:first_name], :name => 'some_idx') } - end - def test_create_table_with_force_true_does_not_drop_nonexisting_table if Person.connection.table_exists?(:testings2) Person.connection.drop_table :testings2 |