mirror of
https://github.com/whippyshou/mastodon
synced 2024-12-01 08:18:48 +09:00
Handle nil and blank cases in Account finders (#3500)
This commit is contained in:
parent
dbccdcc1b1
commit
d1e08bd38c
@ -37,21 +37,25 @@ module AccountFinderConcern
|
|||||||
|
|
||||||
def scoped_accounts
|
def scoped_accounts
|
||||||
Account.unscoped.tap do |scope|
|
Account.unscoped.tap do |scope|
|
||||||
|
scope.merge! with_usernames
|
||||||
scope.merge! matching_username
|
scope.merge! matching_username
|
||||||
scope.merge! matching_domain
|
scope.merge! matching_domain
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_usernames
|
||||||
|
Account.where.not(username: [nil, ''])
|
||||||
|
end
|
||||||
|
|
||||||
def matching_username
|
def matching_username
|
||||||
raise(ActiveRecord::RecordNotFound) if username.blank?
|
Account.where(Account.arel_table[:username].lower.eq username.to_s.downcase)
|
||||||
Account.where(Account.arel_table[:username].lower.eq username.downcase)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def matching_domain
|
def matching_domain
|
||||||
if domain.nil?
|
if domain.nil?
|
||||||
Account.where(domain: nil)
|
Account.where(domain: nil)
|
||||||
else
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,6 +24,14 @@ describe AccountFinderConcern do
|
|||||||
it 'returns nil for regex style username value' do
|
it 'returns nil for regex style username value' do
|
||||||
expect(Account.find_local('al%')).to be_nil
|
expect(Account.find_local('al%')).to be_nil
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '.find_local!' do
|
describe '.find_local!' do
|
||||||
@ -70,6 +78,14 @@ describe AccountFinderConcern do
|
|||||||
it 'returns nil for regex style domain value' do
|
it 'returns nil for regex style domain value' do
|
||||||
expect(Account.find_remote('alice', 'm%')).to be_nil
|
expect(Account.find_remote('alice', 'm%')).to be_nil
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '.find_remote!' do
|
describe '.find_remote!' do
|
||||||
|
Loading…
Reference in New Issue
Block a user