From fe4d5ea786aa82426735b081b6f1581678222814 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 9 Oct 2006 02:14:36 +0000 Subject: Fixed rename_table on SQLite tables with indexes defined (closes #5942) [brandon@opensoul.org] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5260 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/migration_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'activerecord/test/migration_test.rb') diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index fdd21df300..a28532eed7 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -378,6 +378,27 @@ if ActiveRecord::Base.connection.supports_migrations? end end + def test_rename_table_with_an_index + begin + ActiveRecord::Base.connection.create_table :octopuses do |t| + t.column :url, :string + end + ActiveRecord::Base.connection.add_index :octopuses, :url + + ActiveRecord::Base.connection.rename_table :octopuses, :octopi + + # Using explicit id in insert for compatibility across all databases + con = ActiveRecord::Base.connection + assert_nothing_raised { con.execute "INSERT INTO octopi (#{con.quote_column_name('id')}, #{con.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')" } + + assert_equal 'http://www.foreverflying.com/octopus-black7.jpg', ActiveRecord::Base.connection.select_value("SELECT url FROM octopi WHERE id=1") + assert ActiveRecord::Base.connection.indexes(:octopi).first.columns.include?("url") + ensure + ActiveRecord::Base.connection.drop_table :octopuses rescue nil + ActiveRecord::Base.connection.drop_table :octopi rescue nil + end + end + def test_change_column Person.connection.add_column 'people', 'age', :integer old_columns = Person.connection.columns(Person.table_name, "#{name} Columns") -- cgit v1.2.3