Browse files

Fix add_index with a symbol #4891

  • Loading branch information...
1 parent dbbf2fd commit bc52d81306425f8d36b3e6ac767bda53fe06e3b1 @etiennebarrie etiennebarrie committed with tenderlove Jun 18, 2010
View
3 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -274,7 +274,7 @@ def add_index(table_name, column_name, options = {})
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[:name]
else
index_type = options
end
@@ -347,6 +347,7 @@ def index_name(table_name, options) #:nodoc:
# as there's no way to determine the correct answer in that case.
def index_exists?(table_name, index_name, default)
return default unless respond_to?(:indexes)
+ index_name = index_name.to_s
indexes(table_name).detect { |i| i.name == index_name }
end
View
7 activerecord/test/cases/migration_test.rb
@@ -119,6 +119,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, :symbol_index_name, true)
+ assert_nothing_raised { Person.connection.remove_index :people, :name => :symbol_index_name }
+ assert_equal true, !Person.connection.index_exists?(:people, :symbol_index_name, false)
+ 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 bc52d81

Please sign in to comment.