about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-06-01 08:20:36 -0400
committerGitHub <noreply@github.com>2017-06-01 08:20:36 -0400
commitd1e08bd38c029f0b47dfd2f3ba61ca5bb3e414b8 (patch)
tree2071431a9b9c4acae9b12677ecb03f59b26546c3 /app/models
parentdbccdcc1b1e295b7f05a7867936e858ea26f0d6b (diff)
Handle nil and blank cases in Account finders (#3500)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/account_finder_concern.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/models/concerns/account_finder_concern.rb b/app/models/concerns/account_finder_concern.rb
index d3ad519b1..561c7ab9f 100644
--- a/app/models/concerns/account_finder_concern.rb
+++ b/app/models/concerns/account_finder_concern.rb
@@ -37,21 +37,25 @@ module AccountFinderConcern
 
     def scoped_accounts
       Account.unscoped.tap do |scope|
+        scope.merge! with_usernames
         scope.merge! matching_username
         scope.merge! matching_domain
       end
     end
 
+    def with_usernames
+      Account.where.not(username: [nil, ''])
+    end
+
     def matching_username
-      raise(ActiveRecord::RecordNotFound) if username.blank?
-      Account.where(Account.arel_table[:username].lower.eq username.downcase)
+      Account.where(Account.arel_table[:username].lower.eq username.to_s.downcase)
     end
 
     def matching_domain
       if domain.nil?
         Account.where(domain: nil)
       else
-        Account.where(Account.arel_table[:domain].lower.eq domain.downcase)
+        Account.where(Account.arel_table[:domain].lower.eq domain.to_s.downcase)
       end
     end
   end