Skip to content

Commit 57442ec

Browse files
committed
Add uuid_test to re-implement the ActiveRecord test where an invalid UUID is passed to the database.
1 parent 704b432 commit 57442ec

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
require "cases/helper"
4+
require "support/schema_dumping_helper"
5+
6+
module PostgresqlUUIDHelper
7+
def connection
8+
@connection ||= ActiveRecord::Base.connection
9+
end
10+
11+
def drop_table(name)
12+
connection.drop_table name, if_exists: true
13+
end
14+
15+
def uuid_function
16+
connection.supports_pgcrypto_uuid? ? "gen_random_uuid()" : "uuid_generate_v4()"
17+
end
18+
19+
def uuid_default
20+
connection.supports_pgcrypto_uuid? ? {} : { default: uuid_function }
21+
end
22+
end
23+
24+
class PostgresqlUUIDTest < ActiveRecord::PostgreSQLTestCase
25+
include PostgresqlUUIDHelper
26+
include SchemaDumpingHelper
27+
28+
class UUIDType < ActiveRecord::Base
29+
self.table_name = "uuid_data_type"
30+
end
31+
32+
setup do
33+
enable_extension!("uuid-ossp", connection)
34+
enable_extension!("pgcrypto", connection) if connection.supports_pgcrypto_uuid?
35+
36+
connection.create_table "uuid_data_type" do |t|
37+
t.uuid "guid"
38+
end
39+
end
40+
41+
teardown do
42+
drop_table "uuid_data_type"
43+
end
44+
45+
46+
# This test case is nearly identical to the ActiveRecord test, except that
47+
# the input guid is a valid UUID since CockroachDB will raise an exception
48+
# if the UUID is invalid whereas Postgres won't.
49+
def test_uuid_change_case_does_not_mark_dirty
50+
model = UUIDType.create!(guid: "A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11")
51+
model.guid = model.guid.swapcase
52+
assert_not_predicate model, :changed?
53+
end
54+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exclude :test_doesnt_error_when_a_read_query_with_cursors_is_called_while_preventing_writes, "CockroachDB does not currently support declaring a cursor."
1+
exclude :test_doesnt_error_when_a_read_query_with_cursors_is_called_while_preventing_writes, "CockroachDB does not currently support declaring a cursor. See https://github.com/cockroachdb/cockroach/issues/41412."
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exclude :test_doesnt_error_when_a_read_query_with_cursors_is_called_while_preventing_writes, "CockroachDB does not currently support declaring a cursor."
1+
exclude :test_doesnt_error_when_a_read_query_with_cursors_is_called_while_preventing_writes, "CockroachDB does not currently support declaring a cursor. See https://github.com/cockroachdb/cockroach/issues/41412."

test/excludes/PostgresqlMoneyTest.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
exclude :test_update_all_with_money_string, "The money type is not implemented in CockroachDB. See https://github.com/cockroachdb/cockroach/issues/41578."
88
exclude :test_update_all_with_money_big_decimal, "The money type is not implemented in CockroachDB. See https://github.com/cockroachdb/cockroach/issues/41578."
99
exclude :test_update_all_with_money_numeric, "The money type is not implemented in CockroachDB. See https://github.com/cockroachdb/cockroach/issues/41578."
10+
exclude :test_sum_with_type_cast, "The money type is not implemented in CockroachDB. See https://github.com/cockroachdb/cockroach/issues/41578."
11+
exclude :test_pluck_with_type_cast, "The money type is not implemented in CockroachDB. See https://github.com/cockroachdb/cockroach/issues/41578."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
exclude :test_uniqueness_validation_ignores_uuid, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
22
exclude :test_change_column_default, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
33
exclude :test_uuid_formats, "Skipping until we can triage further. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/48"
4+
exclude :test_uuid_change_case_does_not_mark_dirty, "This test is re-implemented by us. The original version tests with an invalid UUID, which causes CockroachDB to raise an exception."

0 commit comments

Comments
 (0)