Skip to content

Commit 8a061a1

Browse files
aidanharanAidan Haran
and
Aidan Haran
authored
Coerce test to handle default case-insensitive collation (#915)
Co-authored-by: Aidan Haran <aharan@fusioneer.com>
1 parent 0e0da50 commit 8a061a1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/cases/coerced_tests.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ def test_validate_uniqueness_with_limit_and_utf8_coerced
2323
end
2424
end
2525
end
26+
27+
# Same as original coerced test except that it handles default SQL Server case-insensitive collation.
28+
coerce_tests! :test_validate_uniqueness_by_default_database_collation
29+
def test_validate_uniqueness_by_default_database_collation_coerced
30+
Topic.validates_uniqueness_of(:author_email_address)
31+
32+
topic1 = Topic.new(author_email_address: "david@loudthinking.com")
33+
topic2 = Topic.new(author_email_address: "David@loudthinking.com")
34+
35+
assert_equal 1, Topic.where(author_email_address: "david@loudthinking.com").count
36+
37+
assert_not topic1.valid?
38+
assert_not topic1.save
39+
40+
# Case insensitive collation (SQL_Latin1_General_CP1_CI_AS) by default.
41+
# Should not allow "David" if "david" exists.
42+
assert_not topic2.valid?
43+
assert_not topic2.save
44+
45+
assert_equal 1, Topic.where(author_email_address: "david@loudthinking.com").count
46+
assert_equal 1, Topic.where(author_email_address: "David@loudthinking.com").count
47+
end
2648
end
2749

2850
require "models/event"

0 commit comments

Comments
 (0)