mirror of https://github.com/mastodon/mastodon
Combine repeated requests in `admin/accounts` controller spec (#29119)
This commit is contained in:
parent
492e25da06
commit
da50217b88
|
@ -9,18 +9,8 @@ RSpec.describe Admin::AccountsController do
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||||
|
let(:params) do
|
||||||
around do |example|
|
{
|
||||||
default_per_page = Account.default_per_page
|
|
||||||
Account.paginates_per 1
|
|
||||||
example.run
|
|
||||||
Account.paginates_per default_per_page
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'filters with parameters' do
|
|
||||||
account_filter = instance_double(AccountFilter, results: Account.all)
|
|
||||||
allow(AccountFilter).to receive(:new).and_return(account_filter)
|
|
||||||
params = {
|
|
||||||
origin: 'local',
|
origin: 'local',
|
||||||
by_domain: 'domain',
|
by_domain: 'domain',
|
||||||
status: 'active',
|
status: 'active',
|
||||||
|
@ -29,25 +19,35 @@ RSpec.describe Admin::AccountsController do
|
||||||
email: 'local-part@domain',
|
email: 'local-part@domain',
|
||||||
ip: '0.0.0.42',
|
ip: '0.0.0.42',
|
||||||
}
|
}
|
||||||
|
|
||||||
get :index, params: params
|
|
||||||
|
|
||||||
expect(AccountFilter).to have_received(:new).with(hash_including(params))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'paginates accounts' do
|
around do |example|
|
||||||
|
default_per_page = Account.default_per_page
|
||||||
|
Account.paginates_per 1
|
||||||
|
example.run
|
||||||
|
Account.paginates_per default_per_page
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
Fabricate(:account)
|
Fabricate(:account)
|
||||||
|
|
||||||
get :index, params: { page: 2 }
|
account_filter = instance_double(AccountFilter, results: Account.all)
|
||||||
|
allow(AccountFilter).to receive(:new).and_return(account_filter)
|
||||||
accounts = assigns(:accounts)
|
|
||||||
expect(accounts.count).to eq 1
|
|
||||||
expect(accounts.klass).to be Account
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns success and paginates and filters with parameters' do
|
||||||
get :index
|
get :index, params: params.merge(page: 2)
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
|
expect(response)
|
||||||
|
.to have_http_status(200)
|
||||||
|
expect(assigns(:accounts))
|
||||||
|
.to have_attributes(
|
||||||
|
count: eq(1),
|
||||||
|
klass: be(Account)
|
||||||
|
)
|
||||||
|
expect(AccountFilter)
|
||||||
|
.to have_received(:new)
|
||||||
|
.with(hash_including(params))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue