From c0a12453418356a837c3f62709fac6fe948047a6 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Tue, 7 May 2013 14:07:50 -0400 Subject: Handle other pk types in PostgreSQL gracefully. In #10410 it was noted that you can no longer create PK's with the type of bigserial in PostgreSQL in 4.0.0.rc1. This is mostly because the newer adapter is checking for column type with the id column instead of just letting it pass through like it did before. Side effects: You may just create a PK column of a type that you really don't want to be your PK. As far as I can tell this was allowed in 3.2.X and perhaps an exception should be raised if you try and do something extremely dumb. --- activerecord/test/cases/primary_keys_test.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index 51ddd406ed..56d0dd6a77 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -219,3 +219,29 @@ if current_adapter?(:MysqlAdapter, :Mysql2Adapter) end end end + +if current_adapter?(:PostgreSQLAdapter) + class PrimaryKeyBigSerialTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + class Widget < ActiveRecord::Base + end + + setup do + @connection = ActiveRecord::Base.connection + @connection.create_table(:widgets, id: :bigserial) { |t| } + end + + teardown do + @connection.drop_table :widgets + end + + def test_bigserial_primary_key + assert_equal "id", Widget.primary_key + assert_equal :integer, Widget.columns_hash[Widget.primary_key].type + + widget = Widget.create! + assert_not_nil widget.id + end + end +end -- cgit v1.2.3