Skip to content

Rails 6.1: Coerce test to handle default case-insensitive collation #915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ def test_validate_uniqueness_with_limit_and_utf8_coerced
end
end
end

# Same as original coerced test except that it handles default SQL Server case-insensitive collation.
coerce_tests! :test_validate_uniqueness_by_default_database_collation
def test_validate_uniqueness_by_default_database_collation_coerced
Topic.validates_uniqueness_of(:author_email_address)

topic1 = Topic.new(author_email_address: "david@loudthinking.com")
topic2 = Topic.new(author_email_address: "David@loudthinking.com")

assert_equal 1, Topic.where(author_email_address: "david@loudthinking.com").count

assert_not topic1.valid?
assert_not topic1.save

# Case insensitive collation (SQL_Latin1_General_CP1_CI_AS) by default.
# Should not allow "David" if "david" exists.
assert_not topic2.valid?
assert_not topic2.save

assert_equal 1, Topic.where(author_email_address: "david@loudthinking.com").count
assert_equal 1, Topic.where(author_email_address: "David@loudthinking.com").count
end
end

require "models/event"
Expand Down