about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/models/concerns/account_finder_concern.rb10
-rw-r--r--spec/models/concerns/account_finder_concern_spec.rb16
2 files changed, 23 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
diff --git a/spec/models/concerns/account_finder_concern_spec.rb b/spec/models/concerns/account_finder_concern_spec.rb
index 05f0f44f2..25f4fdec4 100644
--- a/spec/models/concerns/account_finder_concern_spec.rb
+++ b/spec/models/concerns/account_finder_concern_spec.rb
@@ -24,6 +24,14 @@ describe AccountFinderConcern do
       it 'returns nil for regex style username value' do
         expect(Account.find_local('al%')).to be_nil
       end
+
+      it 'returns nil for nil username value' do
+        expect(Account.find_local(nil)).to be_nil
+      end
+
+      it 'returns nil for blank username value' do
+        expect(Account.find_local('')).to be_nil
+      end
     end
 
     describe '.find_local!' do
@@ -70,6 +78,14 @@ describe AccountFinderConcern do
       it 'returns nil for regex style domain value' do
         expect(Account.find_remote('alice', 'm%')).to be_nil
       end
+
+      it 'returns nil for nil username value' do
+        expect(Account.find_remote(nil, 'domain')).to be_nil
+      end
+
+      it 'returns nil for blank username value' do
+        expect(Account.find_remote('', 'domain')).to be_nil
+      end
     end
 
     describe '.find_remote!' do