Clean up of RSpec/LetSetup
within api/
(#28448)
This commit is contained in:
parent
5976d3702f
commit
cd64a5b2ec
6 changed files with 60 additions and 25 deletions
|
@ -47,11 +47,6 @@ RSpec/ExampleLength:
|
|||
|
||||
RSpec/LetSetup:
|
||||
Exclude:
|
||||
- 'spec/controllers/api/v1/accounts/statuses_controller_spec.rb'
|
||||
- 'spec/controllers/api/v1/filters_controller_spec.rb'
|
||||
- 'spec/controllers/api/v2/admin/accounts_controller_spec.rb'
|
||||
- 'spec/controllers/api/v2/filters/keywords_controller_spec.rb'
|
||||
- 'spec/controllers/api/v2/filters/statuses_controller_spec.rb'
|
||||
- 'spec/controllers/auth/confirmations_controller_spec.rb'
|
||||
- 'spec/controllers/auth/passwords_controller_spec.rb'
|
||||
- 'spec/controllers/auth/sessions_controller_spec.rb'
|
||||
|
|
|
@ -10,11 +10,11 @@ describe Api::V1::Accounts::StatusesController do
|
|||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
Fabricate(:status, account: user.account)
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns expected headers', :aggregate_failures do
|
||||
Fabricate(:status, account: user.account)
|
||||
get :index, params: { account_id: user.account.id, limit: 1 }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
|
@ -30,7 +30,6 @@ describe Api::V1::Accounts::StatusesController do
|
|||
end
|
||||
|
||||
context 'with exclude replies' do
|
||||
let!(:older_statuses) { user.account.statuses.destroy_all }
|
||||
let!(:status) { Fabricate(:status, account: user.account) }
|
||||
let!(:status_self_reply) { Fabricate(:status, account: user.account, thread: status) }
|
||||
|
||||
|
|
|
@ -15,10 +15,15 @@ RSpec.describe Api::V1::FiltersController do
|
|||
describe 'GET #index' do
|
||||
let(:scopes) { 'read:filters' }
|
||||
let!(:filter) { Fabricate(:custom_filter, account: user.account) }
|
||||
let!(:custom_filter_keyword) { Fabricate(:custom_filter_keyword, custom_filter: filter) }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json)
|
||||
.to contain_exactly(
|
||||
include(id: custom_filter_keyword.id.to_s)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -34,28 +34,56 @@ RSpec.describe Api::V2::Admin::AccountsController do
|
|||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
it_behaves_like 'forbidden for wrong role', ''
|
||||
|
||||
[
|
||||
[{ status: 'active', origin: 'local', permissions: 'staff' }, [:admin_account]],
|
||||
[{ by_domain: 'example.org', origin: 'remote' }, [:remote_account]],
|
||||
[{ status: 'suspended' }, [:suspended_remote, :suspended_account]],
|
||||
[{ status: 'disabled' }, [:disabled_account]],
|
||||
[{ status: 'pending' }, [:pending_account]],
|
||||
].each do |params, expected_results|
|
||||
context "when called with #{params.inspect}" do
|
||||
let(:params) { params }
|
||||
context 'when called with status active and origin local and permissions staff' do
|
||||
let(:params) { { status: 'active', origin: 'local', permissions: 'staff' } }
|
||||
|
||||
it "returns the correct accounts (#{expected_results.inspect})" do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
expect(body_json_ids).to eq(expected_results.map { |symbol| send(symbol).id })
|
||||
end
|
||||
|
||||
def body_json_ids
|
||||
body_as_json.map { |a| a[:id].to_i }
|
||||
end
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to eq([admin_account.id])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with by_domain value and origin remote' do
|
||||
let(:params) { { by_domain: 'example.org', origin: 'remote' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to include(remote_account.id)
|
||||
expect(body_json_ids).to_not include(other_remote_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with status suspended' do
|
||||
let(:params) { { status: 'suspended' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to include(suspended_remote.id, suspended_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with status disabled' do
|
||||
let(:params) { { status: 'disabled' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to include(disabled_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with status pending' do
|
||||
let(:params) { { status: 'pending' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to include(pending_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
def body_json_ids
|
||||
body_as_json.map { |a| a[:id].to_i }
|
||||
end
|
||||
|
||||
context 'with limit param' do
|
||||
let(:params) { { limit: 1 } }
|
||||
|
||||
|
|
|
@ -22,6 +22,10 @@ RSpec.describe Api::V2::Filters::KeywordsController do
|
|||
it 'returns http success' do
|
||||
get :index, params: { filter_id: filter.id }
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json)
|
||||
.to contain_exactly(
|
||||
include(id: keyword.id.to_s)
|
||||
)
|
||||
end
|
||||
|
||||
context "when trying to access another's user filters" do
|
||||
|
|
|
@ -22,6 +22,10 @@ RSpec.describe Api::V2::Filters::StatusesController do
|
|||
it 'returns http success' do
|
||||
get :index, params: { filter_id: filter.id }
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json)
|
||||
.to contain_exactly(
|
||||
include(id: status_filter.id.to_s)
|
||||
)
|
||||
end
|
||||
|
||||
context "when trying to access another's user filters" do
|
||||
|
|
Loading…
Reference in a new issue