Change moderation search an account using the username with @ (#24242)

lolsob-rspec
Heitor de Melo Cardozo 2023-04-17 09:16:36 -03:00 committed by GitHub
parent b72a9eb02e
commit a34c422490
2 changed files with 20 additions and 1 deletions

View File

@ -55,7 +55,7 @@ class AccountFilter
when 'by_domain' when 'by_domain'
Account.where(domain: value.to_s.strip) Account.where(domain: value.to_s.strip)
when 'username' when 'username'
Account.matches_username(value.to_s.strip) Account.matches_username(value.to_s.strip.delete_prefix('@'))
when 'display_name' when 'display_name'
Account.matches_display_name(value.to_s.strip) Account.matches_display_name(value.to_s.strip)
when 'email' when 'email'

View File

@ -44,4 +44,23 @@ describe AccountFilter do
expect(filter.results).to match_array [remote_account_one] expect(filter.results).to match_array [remote_account_one]
end end
end end
describe 'with username' do
let!(:local_account) { Fabricate(:account, domain: nil, username: 'validUserName') }
it 'works with @ at the beginning of the username' do
filter = described_class.new(username: '@validUserName')
expect(filter.results).to match_array [local_account]
end
it 'does not work with more than one @ at the beginning of the username' do
filter = described_class.new(username: '@@validUserName')
expect(filter.results).to_not match_array [local_account]
end
it 'does not work with @ outside the beginning of the username' do
filter = described_class.new(username: 'validUserName@')
expect(filter.results).to_not match_array [local_account]
end
end
end end