Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test add_index and remove_index with a symbol name #4891

  • Loading branch information...
commit 8b8730e1390963a8bb3a231ed1a324862d3dc4cf 1 parent 9eca11a
@etiennebarrie etiennebarrie authored tenderlove committed
View
7 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -327,14 +327,12 @@ def rename_column(table_name, column_name, new_column_name)
#
# Note: SQLite doesn't support index length
def add_index(table_name, column_name, options = {})
- options[:name] = options[:name].to_s if options.key?(:name)
-
column_names = Array.wrap(column_name)
index_name = index_name(table_name, :column => column_names)
if Hash === options # legacy support, since this param was a string
index_type = options[:unique] ? "UNIQUE" : ""
- index_name = options[:name] || index_name
+ index_name = options[:name].to_s if options.key?(:name)
else
index_type = options
end
@@ -404,7 +402,8 @@ def index_name(table_name, options) #:nodoc:
# as there's no way to determine the correct answer in that case.
def index_name_exists?(table_name, index_name, default)
return default unless respond_to?(:indexes)
- indexes(table_name).detect { |i| i.name == index_name.to_s }
+ index_name = index_name.to_s
+ indexes(table_name).detect { |i| i.name == index_name }
end
# Returns a string of <tt>CREATE TABLE</tt> SQL statement(s) for recreating the
View
7 activerecord/test/cases/migration_test.rb
@@ -124,6 +124,13 @@ def test_add_index
end
end
+ def test_index_symbol_names
+ assert_nothing_raised { Person.connection.add_index :people, :primary_contact_id, :name => :symbol_index_name }
+ assert Person.connection.index_exists?(:people, :primary_contact_id, :name => :symbol_index_name)
+ assert_nothing_raised { Person.connection.remove_index :people, :name => :symbol_index_name }
+ assert !Person.connection.index_exists?(:people, :primary_contact_id, :name => :symbol_index_name)
+ end
+
def test_add_index_length_limit
good_index_name = 'x' * Person.connection.index_name_length
too_long_index_name = good_index_name + 'x'

0 comments on commit 8b8730e

Please sign in to comment.
Something went wrong with that request. Please try again.