Permalink
Browse files

forwardport #9388 rename/remove column preserves custom PK.

  • Loading branch information...
1 parent cad397e commit 2d4e3fecc28c40eef461c1242ebf17384d6e38fb @senny senny committed Feb 23, 2013
Showing with 15 additions and 1 deletion.
  1. +15 −1 activerecord/test/cases/migration/rename_column_test.rb
@@ -128,7 +128,7 @@ def test_remove_column_with_multi_column_index
assert_equal 1, connection.indexes('test_models').size
remove_column("test_models", "hat_size")
- # Every database and/or database adapter has their own behavior
+ # Every database and/or database adapter has their own behavior
# if it drops the multi-column index when any of the indexed columns dropped by remove_column.
if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
assert_equal [], connection.indexes('test_models').map(&:name)
@@ -245,6 +245,20 @@ def test_change_column_default_to_null
def test_remove_column_no_second_parameter_raises_exception
assert_raise(ArgumentError) { connection.remove_column("funny") }
end
+
+ def test_removing_and_renaming_column_preserves_custom_primary_key
+ connection.create_table "my_table", primary_key: "my_table_id", force: true do |t|
+ t.integer "col_one"
+ t.string "col_two", limit: 128, null: false
+ end
+
+ remove_column("my_table", "col_two")
+ rename_column("my_table", "col_one", "col_three")
+
+ assert_equal 'my_table_id', connection.primary_key('my_table')
+ ensure
+ connection.drop_table(:my_table) rescue nil
+ end
end
end
end

0 comments on commit 2d4e3fe

Please sign in to comment.