diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-03-14 18:21:00 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-03-14 18:21:00 -0700 |
commit | d7587943711e96e0335c40452d77869a479c1722 (patch) | |
tree | d74e7472c20062ffaf49f08ad6ffe97d63b53823 /activerecord/test | |
parent | cf065777d0a57f5975b2a6d1657ae8e492b855dc (diff) | |
download | rails-d7587943711e96e0335c40452d77869a479c1722.tar.gz rails-d7587943711e96e0335c40452d77869a479c1722.tar.bz2 rails-d7587943711e96e0335c40452d77869a479c1722.zip |
you can provide uuid_generate_v4 as the default value for uuid columns
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/uuid_test.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb new file mode 100644 index 0000000000..53002c5265 --- /dev/null +++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb @@ -0,0 +1,43 @@ +# encoding: utf-8 + +require "cases/helper" +require 'active_record/base' +require 'active_record/connection_adapters/postgresql_adapter' + +class PostgresqlUUIDTest < ActiveRecord::TestCase + class UUID < ActiveRecord::Base + self.table_name = 'pg_uuids' + end + + def setup + @connection = ActiveRecord::Base.connection + + unless @connection.supports_extensions? + return skip "do not test on PG without uuid-ossp" + end + + unless @connection.extension_enabled?('uuid-ossp') + @connection.enable_extension 'uuid-ossp' + @connection.commit_db_transaction + end + + @connection.reconnect! + + @connection.transaction do + @connection.create_table('pg_uuids', id: :uuid) do |t| + t.string 'name' + t.uuid 'other_uuid', default: 'uuid_generate_v4()' + end + end + end + + def teardown + @connection.execute 'drop table if exists pg_uuids' + end + + def test_auto_create_uuid + u = UUID.create + u.reload + assert_not_nil u.other_uuid + end +end |