55 lines
2.5 KiB
Diff
55 lines
2.5 KiB
Diff
Fix for gentoo bug 329435 as reported in
|
|
https://rails.lighthouseapp.com/projects/8994/tickets/4891-rails-238-dbmigrate-gives-undefined-method-length-for-any_indexsymbol
|
|
|
|
From 1ceabd624b8bc8c68ac98d951160aaff299d18a6 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= <etienne.barrie@gmail.com>
|
|
Date: Fri, 18 Jun 2010 16:07:17 +0200
|
|
Subject: [PATCH] Fix add_index with a symbol #4891
|
|
|
|
---
|
|
.../abstract/schema_statements.rb | 3 ++-
|
|
activerecord/test/cases/migration_test.rb | 7 +++++++
|
|
2 files changed, 9 insertions(+), 1 deletions(-)
|
|
|
|
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
|
|
index 4fa5881..ddac1f7 100644
|
|
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
|
|
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
|
|
@@ -273,7 +273,7 @@ module ActiveRecord
|
|
|
|
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
|
|
@@ -346,6 +346,7 @@ module ActiveRecord
|
|
# 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
|
|
|
|
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
|
|
index 8517fe2..4b10062 100644
|
|
--- a/activerecord/test/cases/migration_test.rb
|
|
+++ b/activerecord/test/cases/migration_test.rb
|
|
@@ -119,6 +119,13 @@ if ActiveRecord::Base.connection.supports_migrations?
|
|
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'
|
|
--
|
|
1.7.1
|
|
|