diff options
author | Matthew Draper <matthew@trebex.net> | 2015-12-18 14:13:46 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2015-12-18 14:13:46 +1030 |
commit | c316ce9ba4d67045029c8463dc7e04ea04e9ddad (patch) | |
tree | cc7d3712208d40faf00c07eb4e61915f9de974de /activerecord/test/cases/migration | |
parent | 4a58aef7e3035e775b4cd6cc65575c8ed02cd8af (diff) | |
parent | 8ceb883b0630e0d010fbef0c621cc9690b0bcad6 (diff) | |
download | rails-c316ce9ba4d67045029c8463dc7e04ea04e9ddad.tar.gz rails-c316ce9ba4d67045029c8463dc7e04ea04e9ddad.tar.bz2 rails-c316ce9ba4d67045029c8463dc7e04ea04e9ddad.zip |
Merge pull request #19456 from greysteil/index-exists-behaviour
Ignore index name in `index_exists?` when not passed a name to check for
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r-- | activerecord/test/cases/migration/compatibility_test.rb | 42 | ||||
-rw-r--r-- | activerecord/test/cases/migration/index_test.rb | 10 |
2 files changed, 52 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/compatibility_test.rb b/activerecord/test/cases/migration/compatibility_test.rb new file mode 100644 index 0000000000..267d2fcccc --- /dev/null +++ b/activerecord/test/cases/migration/compatibility_test.rb @@ -0,0 +1,42 @@ +require 'cases/helper' + +module ActiveRecord + class Migration + class CompatibilityTest < ActiveRecord::TestCase + attr_reader :connection + self.use_transactional_tests = false + + def setup + super + @connection = ActiveRecord::Base.connection + @verbose_was = ActiveRecord::Migration.verbose + ActiveRecord::Migration.verbose = false + + connection.create_table :testings do |t| + t.column :foo, :string, :limit => 100 + t.column :bar, :string, :limit => 100 + end + end + + teardown do + connection.drop_table :testings rescue nil + ActiveRecord::Migration.verbose = @verbose_was + end + + def test_migration_doesnt_remove_named_index + connection.add_index :testings, :foo, :name => "custom_index_name" + + migration = Class.new(ActiveRecord::Migration[4.2]) { + def version; 101 end + def migrate(x) + remove_index :testings, :foo + end + }.new + + assert connection.index_exists?(:testings, :foo, name: "custom_index_name") + assert_raise(StandardError) { ActiveRecord::Migrator.new(:up, [migration]).migrate } + assert connection.index_exists?(:testings, :foo, name: "custom_index_name") + end + end + end +end diff --git a/activerecord/test/cases/migration/index_test.rb b/activerecord/test/cases/migration/index_test.rb index 33ff0ee73d..5abd37bfa2 100644 --- a/activerecord/test/cases/migration/index_test.rb +++ b/activerecord/test/cases/migration/index_test.rb @@ -130,7 +130,17 @@ module ActiveRecord def test_named_index_exists connection.add_index :testings, :foo, :name => "custom_index_name" + assert connection.index_exists?(:testings, :foo) assert connection.index_exists?(:testings, :foo, :name => "custom_index_name") + assert !connection.index_exists?(:testings, :foo, :name => "other_index_name") + end + + def test_remove_named_index + connection.add_index :testings, :foo, :name => "custom_index_name" + + assert connection.index_exists?(:testings, :foo) + connection.remove_index :testings, :foo + assert !connection.index_exists?(:testings, :foo) end def test_add_index_attribute_length_limit |