aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-02-21 01:59:43 +0900
committerGitHub <noreply@github.com>2019-02-21 01:59:43 +0900
commitdfa857ef25b5abf7485e4f7115e4a311e00c599c (patch)
treeaa5e16c17dc13dd5af358d1973ccf3c8fd229ab6 /activerecord/test/cases/adapters
parent5b756f4342d2b48a0dccb6d7aa48bcb3f0048e84 (diff)
parent6735a0719d43b08a18bb5ea544ad2af0935138a5 (diff)
downloadrails-dfa857ef25b5abf7485e4f7115e4a311e00c599c.tar.gz
rails-dfa857ef25b5abf7485e4f7115e4a311e00c599c.tar.bz2
rails-dfa857ef25b5abf7485e4f7115e4a311e00c599c.zip
Merge pull request #35263 from hatch-carl/reduce-postgres-uuid-allocations
Reduce unused allocations when casting UUIDs for Postgres
Diffstat (limited to 'activerecord/test/cases/adapters')
-rw-r--r--activerecord/test/cases/adapters/postgresql/uuid_test.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb
index 6591d50d06..d2d8ea8042 100644
--- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb
@@ -120,6 +120,16 @@ class PostgresqlUUIDTest < ActiveRecord::PostgreSQLTestCase
assert_empty UUIDType.where(guid: "foobar")
end
+ class DuckUUID
+ def initialize(uuid)
+ @uuid = uuid
+ end
+
+ def to_s
+ @uuid
+ end
+ end
+
def test_acceptable_uuid_regex
# Valid uuids
["A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11",
@@ -131,9 +141,11 @@ class PostgresqlUUIDTest < ActiveRecord::PostgreSQLTestCase
# so we shouldn't block it either. (Pay attention to "fb6d" – the "f" here
# is invalid – it must be one of 8, 9, A, B, a, b according to the spec.)
"{a0eebc99-9c0b-4ef8-fb6d-6bb9bd380a11}",
+ # Support Object-Oriented UUIDs which respond to #to_s
+ DuckUUID.new("A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11"),
].each do |valid_uuid|
uuid = UUIDType.new guid: valid_uuid
- assert_not_nil uuid.guid
+ assert_instance_of String, uuid.guid
end
# Invalid uuids