Skip to content

Commit

Permalink
Merge pull request #10404 from chadmoone/fix-pg-uuid-default
Browse files Browse the repository at this point in the history
Allow override of PostgreSQL UUID primary key default
  • Loading branch information
rafaelfranca committed May 13, 2013
1 parent 7950c0f commit 0e8e1b6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions activerecord/test/cases/adapters/postgresql/uuid_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,34 @@ def test_id_allows_default_override_via_nil
assert_nil col_desc["default"]
end
end

class PostgresqlUUIDTestNilDefault < ActiveRecord::TestCase
class UUID < ActiveRecord::Base
self.table_name = 'pg_uuids'
end

def setup
@connection = ActiveRecord::Base.connection

@connection.reconnect!

@connection.transaction do
@connection.create_table('pg_uuids', id: false) do |t|
t.primary_key :id, :uuid, default: nil
t.string 'name'
end
end
end

def teardown
@connection.execute 'drop table if exists pg_uuids'
end

def test_id_allows_default_override_via_nil
col_desc = @connection.execute("SELECT pg_get_expr(d.adbin, d.adrelid) as default
FROM pg_attribute a
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attname='id' AND a.attrelid = 'pg_uuids'::regclass").first
assert_nil col_desc["default"]
end
end

0 comments on commit 0e8e1b6

Please sign in to comment.