From 61a7390b666dc40beda291da426436a9d36f4288 Mon Sep 17 00:00:00 2001 From: abcang Date: Sat, 1 Feb 2020 23:42:24 +0900 Subject: Search account domain in lowercase (#13016) * Search account domain in lowercase * fix rubocop error * fix spec/models/account_spec.rb --- app/validators/unique_username_validator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/validators') diff --git a/app/validators/unique_username_validator.rb b/app/validators/unique_username_validator.rb index 4e24e3f5f..f87eb06ba 100644 --- a/app/validators/unique_username_validator.rb +++ b/app/validators/unique_username_validator.rb @@ -7,8 +7,9 @@ class UniqueUsernameValidator < ActiveModel::Validator return if account.username.nil? normalized_username = account.username.downcase + normalized_domain = account.domain&.downcase - scope = Account.where(domain: nil).where('lower(username) = ?', normalized_username) + scope = Account.where(Account.arel_table[:username].lower.eq normalized_username).where(Account.arel_table[:domain].lower.eq normalized_domain) scope = scope.where.not(id: account.id) if account.persisted? account.errors.add(:username, :taken) if scope.exists? -- cgit