aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration
diff options
context:
space:
mode:
authorGrey Baker <greysteil@gmail.com>2015-04-03 09:55:53 +0100
committerGrey Baker <greysteil@gmail.com>2015-12-15 21:06:07 +0000
commit8ceb883b0630e0d010fbef0c621cc9690b0bcad6 (patch)
treeb2480a8bc75739dfb17e67313c54fe252424ab53 /activerecord/test/cases/migration
parent9771f5e178ebc1b8c5a61f813373ca3b7bd983c8 (diff)
downloadrails-8ceb883b0630e0d010fbef0c621cc9690b0bcad6.tar.gz
rails-8ceb883b0630e0d010fbef0c621cc9690b0bcad6.tar.bz2
rails-8ceb883b0630e0d010fbef0c621cc9690b0bcad6.zip
Support removing custom-names indexes when only specifying column names
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r--activerecord/test/cases/migration/compatibility_test.rb42
-rw-r--r--activerecord/test/cases/migration/index_test.rb8
2 files changed, 50 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 70169e501c..5b3d13d2f7 100644
--- a/activerecord/test/cases/migration/index_test.rb
+++ b/activerecord/test/cases/migration/index_test.rb
@@ -135,6 +135,14 @@ module ActiveRecord
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
connection.add_index :testings, [:foo, :bar], :length => {:foo => 10, :bar => nil}