Fix RSpec/DescribedClass
cop (#25104)
This commit is contained in:
parent
1e243e2df7
commit
c42591356d
66 changed files with 347 additions and 414 deletions
|
@ -362,7 +362,7 @@ RSpec.describe Account do
|
|||
suspended: true
|
||||
)
|
||||
|
||||
results = Account.search_for('username')
|
||||
results = described_class.search_for('username')
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -375,7 +375,7 @@ RSpec.describe Account do
|
|||
|
||||
match.user.update(approved: false)
|
||||
|
||||
results = Account.search_for('username')
|
||||
results = described_class.search_for('username')
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -388,7 +388,7 @@ RSpec.describe Account do
|
|||
|
||||
match.user.update(confirmed_at: nil)
|
||||
|
||||
results = Account.search_for('username')
|
||||
results = described_class.search_for('username')
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -400,7 +400,7 @@ RSpec.describe Account do
|
|||
domain: 'example.com'
|
||||
)
|
||||
|
||||
results = Account.search_for('A?l\i:c e')
|
||||
results = described_class.search_for('A?l\i:c e')
|
||||
expect(results).to eq [match]
|
||||
end
|
||||
|
||||
|
@ -412,7 +412,7 @@ RSpec.describe Account do
|
|||
domain: 'example.com'
|
||||
)
|
||||
|
||||
results = Account.search_for('display')
|
||||
results = described_class.search_for('display')
|
||||
expect(results).to eq [match]
|
||||
end
|
||||
|
||||
|
@ -424,7 +424,7 @@ RSpec.describe Account do
|
|||
domain: 'example.com'
|
||||
)
|
||||
|
||||
results = Account.search_for('username')
|
||||
results = described_class.search_for('username')
|
||||
expect(results).to eq [match]
|
||||
end
|
||||
|
||||
|
@ -436,19 +436,19 @@ RSpec.describe Account do
|
|||
domain: 'example.com'
|
||||
)
|
||||
|
||||
results = Account.search_for('example')
|
||||
results = described_class.search_for('example')
|
||||
expect(results).to eq [match]
|
||||
end
|
||||
|
||||
it 'limits by 10 by default' do
|
||||
11.times.each { Fabricate(:account, display_name: 'Display Name') }
|
||||
results = Account.search_for('display')
|
||||
results = described_class.search_for('display')
|
||||
expect(results.size).to eq 10
|
||||
end
|
||||
|
||||
it 'accepts arbitrary limits' do
|
||||
2.times.each { Fabricate(:account, display_name: 'Display Name') }
|
||||
results = Account.search_for('display', limit: 1)
|
||||
results = described_class.search_for('display', limit: 1)
|
||||
expect(results.size).to eq 1
|
||||
end
|
||||
|
||||
|
@ -458,7 +458,7 @@ RSpec.describe Account do
|
|||
{ display_name: 'Display Name', username: 'username', domain: 'example.com' },
|
||||
].map(&method(:Fabricate).curry(2).call(:account))
|
||||
|
||||
results = Account.search_for('username')
|
||||
results = described_class.search_for('username')
|
||||
expect(results).to eq matches
|
||||
end
|
||||
end
|
||||
|
@ -476,7 +476,7 @@ RSpec.describe Account do
|
|||
)
|
||||
account.follow!(match)
|
||||
|
||||
results = Account.advanced_search_for('A?l\i:c e', account, limit: 10, following: true)
|
||||
results = described_class.advanced_search_for('A?l\i:c e', account, limit: 10, following: true)
|
||||
expect(results).to eq [match]
|
||||
end
|
||||
|
||||
|
@ -488,7 +488,7 @@ RSpec.describe Account do
|
|||
domain: 'example.com'
|
||||
)
|
||||
|
||||
results = Account.advanced_search_for('A?l\i:c e', account, limit: 10, following: true)
|
||||
results = described_class.advanced_search_for('A?l\i:c e', account, limit: 10, following: true)
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -501,7 +501,7 @@ RSpec.describe Account do
|
|||
suspended: true
|
||||
)
|
||||
|
||||
results = Account.advanced_search_for('username', account, limit: 10, following: true)
|
||||
results = described_class.advanced_search_for('username', account, limit: 10, following: true)
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -514,7 +514,7 @@ RSpec.describe Account do
|
|||
|
||||
match.user.update(approved: false)
|
||||
|
||||
results = Account.advanced_search_for('username', account, limit: 10, following: true)
|
||||
results = described_class.advanced_search_for('username', account, limit: 10, following: true)
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -527,7 +527,7 @@ RSpec.describe Account do
|
|||
|
||||
match.user.update(confirmed_at: nil)
|
||||
|
||||
results = Account.advanced_search_for('username', account, limit: 10, following: true)
|
||||
results = described_class.advanced_search_for('username', account, limit: 10, following: true)
|
||||
expect(results).to eq []
|
||||
end
|
||||
end
|
||||
|
@ -541,7 +541,7 @@ RSpec.describe Account do
|
|||
suspended: true
|
||||
)
|
||||
|
||||
results = Account.advanced_search_for('username', account)
|
||||
results = described_class.advanced_search_for('username', account)
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -554,7 +554,7 @@ RSpec.describe Account do
|
|||
|
||||
match.user.update(approved: false)
|
||||
|
||||
results = Account.advanced_search_for('username', account)
|
||||
results = described_class.advanced_search_for('username', account)
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -567,7 +567,7 @@ RSpec.describe Account do
|
|||
|
||||
match.user.update(confirmed_at: nil)
|
||||
|
||||
results = Account.advanced_search_for('username', account)
|
||||
results = described_class.advanced_search_for('username', account)
|
||||
expect(results).to eq []
|
||||
end
|
||||
|
||||
|
@ -579,19 +579,19 @@ RSpec.describe Account do
|
|||
domain: 'example.com'
|
||||
)
|
||||
|
||||
results = Account.advanced_search_for('A?l\i:c e', account)
|
||||
results = described_class.advanced_search_for('A?l\i:c e', account)
|
||||
expect(results).to eq [match]
|
||||
end
|
||||
|
||||
it 'limits by 10 by default' do
|
||||
11.times { Fabricate(:account, display_name: 'Display Name') }
|
||||
results = Account.advanced_search_for('display', account)
|
||||
results = described_class.advanced_search_for('display', account)
|
||||
expect(results.size).to eq 10
|
||||
end
|
||||
|
||||
it 'accepts arbitrary limits' do
|
||||
2.times { Fabricate(:account, display_name: 'Display Name') }
|
||||
results = Account.advanced_search_for('display', account, limit: 1)
|
||||
results = described_class.advanced_search_for('display', account, limit: 1)
|
||||
expect(results.size).to eq 1
|
||||
end
|
||||
|
||||
|
@ -600,7 +600,7 @@ RSpec.describe Account do
|
|||
followed_match = Fabricate(:account, username: 'Matcher')
|
||||
Fabricate(:follow, account: account, target_account: followed_match)
|
||||
|
||||
results = Account.advanced_search_for('match', account)
|
||||
results = described_class.advanced_search_for('match', account)
|
||||
expect(results).to eq [followed_match, match]
|
||||
expect(results.first.rank).to be > results.last.rank
|
||||
end
|
||||
|
@ -639,31 +639,31 @@ RSpec.describe Account do
|
|||
|
||||
describe '.following_map' do
|
||||
it 'returns an hash' do
|
||||
expect(Account.following_map([], 1)).to be_a Hash
|
||||
expect(described_class.following_map([], 1)).to be_a Hash
|
||||
end
|
||||
end
|
||||
|
||||
describe '.followed_by_map' do
|
||||
it 'returns an hash' do
|
||||
expect(Account.followed_by_map([], 1)).to be_a Hash
|
||||
expect(described_class.followed_by_map([], 1)).to be_a Hash
|
||||
end
|
||||
end
|
||||
|
||||
describe '.blocking_map' do
|
||||
it 'returns an hash' do
|
||||
expect(Account.blocking_map([], 1)).to be_a Hash
|
||||
expect(described_class.blocking_map([], 1)).to be_a Hash
|
||||
end
|
||||
end
|
||||
|
||||
describe '.requested_map' do
|
||||
it 'returns an hash' do
|
||||
expect(Account.requested_map([], 1)).to be_a Hash
|
||||
expect(described_class.requested_map([], 1)).to be_a Hash
|
||||
end
|
||||
end
|
||||
|
||||
describe '.requested_by_map' do
|
||||
it 'returns an hash' do
|
||||
expect(Account.requested_by_map([], 1)).to be_a Hash
|
||||
expect(described_class.requested_by_map([], 1)).to be_a Hash
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -834,7 +834,7 @@ RSpec.describe Account do
|
|||
{ username: 'b', domain: 'b' },
|
||||
].map(&method(:Fabricate).curry(2).call(:account))
|
||||
|
||||
expect(Account.where('id > 0').alphabetic).to eq matches
|
||||
expect(described_class.where('id > 0').alphabetic).to eq matches
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -843,7 +843,7 @@ RSpec.describe Account do
|
|||
match = Fabricate(:account, display_name: 'pattern and suffix')
|
||||
Fabricate(:account, display_name: 'prefix and pattern')
|
||||
|
||||
expect(Account.matches_display_name('pattern')).to eq [match]
|
||||
expect(described_class.matches_display_name('pattern')).to eq [match]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -852,24 +852,24 @@ RSpec.describe Account do
|
|||
match = Fabricate(:account, username: 'pattern_and_suffix')
|
||||
Fabricate(:account, username: 'prefix_and_pattern')
|
||||
|
||||
expect(Account.matches_username('pattern')).to eq [match]
|
||||
expect(described_class.matches_username('pattern')).to eq [match]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'by_domain_and_subdomains' do
|
||||
it 'returns exact domain matches' do
|
||||
account = Fabricate(:account, domain: 'example.com')
|
||||
expect(Account.by_domain_and_subdomains('example.com')).to eq [account]
|
||||
expect(described_class.by_domain_and_subdomains('example.com')).to eq [account]
|
||||
end
|
||||
|
||||
it 'returns subdomains' do
|
||||
account = Fabricate(:account, domain: 'foo.example.com')
|
||||
expect(Account.by_domain_and_subdomains('example.com')).to eq [account]
|
||||
expect(described_class.by_domain_and_subdomains('example.com')).to eq [account]
|
||||
end
|
||||
|
||||
it 'does not return partially matching domains' do
|
||||
account = Fabricate(:account, domain: 'grexample.com')
|
||||
expect(Account.by_domain_and_subdomains('example.com')).to_not eq [account]
|
||||
expect(described_class.by_domain_and_subdomains('example.com')).to_not eq [account]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -877,7 +877,7 @@ RSpec.describe Account do
|
|||
it 'returns an array of accounts who have a domain' do
|
||||
account_1 = Fabricate(:account, domain: nil)
|
||||
account_2 = Fabricate(:account, domain: 'example.com')
|
||||
expect(Account.remote).to contain_exactly(account_2)
|
||||
expect(described_class.remote).to contain_exactly(account_2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -885,7 +885,7 @@ RSpec.describe Account do
|
|||
it 'returns an array of accounts who do not have a domain' do
|
||||
account_1 = Fabricate(:account, domain: nil)
|
||||
account_2 = Fabricate(:account, domain: 'example.com')
|
||||
expect(Account.where('id > 0').local).to contain_exactly(account_1)
|
||||
expect(described_class.where('id > 0').local).to contain_exactly(account_1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -896,14 +896,14 @@ RSpec.describe Account do
|
|||
matches[index] = Fabricate(:account, domain: matches[index])
|
||||
end
|
||||
|
||||
expect(Account.where('id > 0').partitioned).to match_array(matches)
|
||||
expect(described_class.where('id > 0').partitioned).to match_array(matches)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'recent' do
|
||||
it 'returns a relation of accounts sorted by recent creation' do
|
||||
matches = Array.new(2) { Fabricate(:account) }
|
||||
expect(Account.where('id > 0').recent).to match_array(matches)
|
||||
expect(described_class.where('id > 0').recent).to match_array(matches)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -911,7 +911,7 @@ RSpec.describe Account do
|
|||
it 'returns an array of accounts who are silenced' do
|
||||
account_1 = Fabricate(:account, silenced: true)
|
||||
account_2 = Fabricate(:account, silenced: false)
|
||||
expect(Account.silenced).to contain_exactly(account_1)
|
||||
expect(described_class.silenced).to contain_exactly(account_1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -919,7 +919,7 @@ RSpec.describe Account do
|
|||
it 'returns an array of accounts who are suspended' do
|
||||
account_1 = Fabricate(:account, suspended: true)
|
||||
account_2 = Fabricate(:account, suspended: false)
|
||||
expect(Account.suspended).to contain_exactly(account_1)
|
||||
expect(described_class.suspended).to contain_exactly(account_1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -941,18 +941,18 @@ RSpec.describe Account do
|
|||
end
|
||||
|
||||
it 'returns every usable non-suspended account' do
|
||||
expect(Account.searchable).to contain_exactly(silenced_local, silenced_remote, local_account, remote_account)
|
||||
expect(described_class.searchable).to contain_exactly(silenced_local, silenced_remote, local_account, remote_account)
|
||||
end
|
||||
|
||||
it 'does not mess with previously-applied scopes' do
|
||||
expect(Account.where.not(id: remote_account.id).searchable).to contain_exactly(silenced_local, silenced_remote, local_account)
|
||||
expect(described_class.where.not(id: remote_account.id).searchable).to contain_exactly(silenced_local, silenced_remote, local_account)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when is local' do
|
||||
it 'generates keys' do
|
||||
account = Account.create!(domain: nil, username: Faker::Internet.user_name(separators: ['_']))
|
||||
account = described_class.create!(domain: nil, username: Faker::Internet.user_name(separators: ['_']))
|
||||
expect(account.keypair).to be_private
|
||||
expect(account.keypair).to be_public
|
||||
end
|
||||
|
@ -961,12 +961,12 @@ RSpec.describe Account do
|
|||
context 'when is remote' do
|
||||
it 'does not generate keys' do
|
||||
key = OpenSSL::PKey::RSA.new(1024).public_key
|
||||
account = Account.create!(domain: 'remote', username: Faker::Internet.user_name(separators: ['_']), public_key: key.to_pem)
|
||||
account = described_class.create!(domain: 'remote', username: Faker::Internet.user_name(separators: ['_']), public_key: key.to_pem)
|
||||
expect(account.keypair.params).to eq key.params
|
||||
end
|
||||
|
||||
it 'normalizes domain' do
|
||||
account = Account.create!(domain: 'にゃん', username: Faker::Internet.user_name(separators: ['_']))
|
||||
account = described_class.create!(domain: 'にゃん', username: Faker::Internet.user_name(separators: ['_']))
|
||||
expect(account.domain).to eq 'xn--r9j5b5b'
|
||||
end
|
||||
end
|
||||
|
@ -986,7 +986,7 @@ RSpec.describe Account do
|
|||
threads = Array.new(increment_by) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
Account.find(subject.id).increment_count!(:followers_count)
|
||||
described_class.find(subject.id).increment_count!(:followers_count)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue