diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-04-03 10:46:46 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-04-03 10:46:46 +0200 |
commit | bd34a950dc7e21abe1340f630082c86197ad9dfc (patch) | |
tree | ab7895aa35069b131e798c875392f2d9061ba874 /activerecord | |
parent | c0e0e80fccf350ae5b59c9b17ec45577ff60f3cb (diff) | |
parent | 1f432c54658cf54608a6e37b70b8dc8e40521502 (diff) | |
download | rails-bd34a950dc7e21abe1340f630082c86197ad9dfc.tar.gz rails-bd34a950dc7e21abe1340f630082c86197ad9dfc.tar.bz2 rails-bd34a950dc7e21abe1340f630082c86197ad9dfc.zip |
Merge branch 'lavrovdv-patch-1'
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/uuid_test.rb | 5 |
3 files changed, 21 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index acd3d395c5..f7718394af 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,11 @@ +* Treat blank UUID values as `nil`. + + Example: + + Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil> + + *Dmitry Lavrov* + * Enable support for materialized views on PostgreSQL >= 9.3. *Dave Lee* diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 57bdc3bb19..9e898015a6 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -330,6 +330,13 @@ This is not reliable and will be removed in the future. end end + class Uuid < Type + def type; :uuid end + def type_cast(value) + value.presence + end + end + class TypeMap def initialize @mapping = {} @@ -418,10 +425,10 @@ This is not reliable and will be removed in the future. register_type 'json', OID::Json.new register_type 'cidr', OID::Cidr.new register_type 'inet', OID::Inet.new + register_type 'uuid', OID::Uuid.new register_type 'xml', SpecializedString.new(:xml) register_type 'tsvector', SpecializedString.new(:tsvector) register_type 'macaddr', SpecializedString.new(:macaddr) - register_type 'uuid', SpecializedString.new(:uuid) register_type 'citext', SpecializedString.new(:citext) register_type 'ltree', SpecializedString.new(:ltree) diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb index f79a7a598b..9e03ea6bee 100644 --- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb +++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb @@ -50,6 +50,11 @@ class PostgresqlUUIDTest < ActiveRecord::TestCase assert_not column.array end + def test_treat_blank_uuid_as_nil + UUIDType.create! guid: '' + assert_equal(nil, UUIDType.last.guid) + end + def test_uuid_formats ["A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11", "{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}", |