aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql
diff options
context:
space:
mode:
authorChad Moone <chadmoone@gmail.com>2013-04-25 00:46:40 -0400
committerChad Moone <chadmoone@gmail.com>2013-05-01 19:07:17 -0400
commit55c40c0ecec50936c439548b440216c62aa4ccbb (patch)
tree0bba0645be78bfa516f52af09140ba445970d641 /activerecord/test/cases/adapters/postgresql
parentf7f8b7ccfc2fe61c0834041d2e211dd9dfdfbbc8 (diff)
downloadrails-55c40c0ecec50936c439548b440216c62aa4ccbb.tar.gz
rails-55c40c0ecec50936c439548b440216c62aa4ccbb.tar.bz2
rails-55c40c0ecec50936c439548b440216c62aa4ccbb.zip
allow override of uuid_generate_v4() default by passing default: nil
without this, it's not possible to use UUID primary keys without uuid-ossp installed and activated
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql')
-rw-r--r--activerecord/test/cases/adapters/postgresql/uuid_test.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb
index c0c0e8898c..edf18cb7a7 100644
--- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb
@@ -51,3 +51,34 @@ class PostgresqlUUIDTest < ActiveRecord::TestCase
assert_not_nil u.other_uuid
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