Clean up of `RSpec/LetSetup` within `api/` (#28448)

th-new
Matt Jankowski 2023-12-21 05:10:18 -05:00 committed by GitHub
parent 5976d3702f
commit cd64a5b2ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 25 deletions

View File

@ -47,11 +47,6 @@ RSpec/ExampleLength:
RSpec/LetSetup: RSpec/LetSetup:
Exclude: 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/confirmations_controller_spec.rb'
- 'spec/controllers/auth/passwords_controller_spec.rb' - 'spec/controllers/auth/passwords_controller_spec.rb'
- 'spec/controllers/auth/sessions_controller_spec.rb' - 'spec/controllers/auth/sessions_controller_spec.rb'

View File

@ -10,11 +10,11 @@ describe Api::V1::Accounts::StatusesController do
before do before do
allow(controller).to receive(:doorkeeper_token) { token } allow(controller).to receive(:doorkeeper_token) { token }
Fabricate(:status, account: user.account)
end end
describe 'GET #index' do describe 'GET #index' do
it 'returns expected headers', :aggregate_failures do it 'returns expected headers', :aggregate_failures do
Fabricate(:status, account: user.account)
get :index, params: { account_id: user.account.id, limit: 1 } get :index, params: { account_id: user.account.id, limit: 1 }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
@ -30,7 +30,6 @@ describe Api::V1::Accounts::StatusesController do
end end
context 'with exclude replies' do context 'with exclude replies' do
let!(:older_statuses) { user.account.statuses.destroy_all }
let!(:status) { Fabricate(:status, account: user.account) } let!(:status) { Fabricate(:status, account: user.account) }
let!(:status_self_reply) { Fabricate(:status, account: user.account, thread: status) } let!(:status_self_reply) { Fabricate(:status, account: user.account, thread: status) }

View File

@ -15,10 +15,15 @@ RSpec.describe Api::V1::FiltersController do
describe 'GET #index' do describe 'GET #index' do
let(:scopes) { 'read:filters' } let(:scopes) { 'read:filters' }
let!(:filter) { Fabricate(:custom_filter, account: user.account) } let!(:filter) { Fabricate(:custom_filter, account: user.account) }
let!(:custom_filter_keyword) { Fabricate(:custom_filter_keyword, custom_filter: filter) }
it 'returns http success' do it 'returns http success' do
get :index get :index
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(body_as_json)
.to contain_exactly(
include(id: custom_filter_keyword.id.to_s)
)
end end
end end

View File

@ -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 scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', '' it_behaves_like 'forbidden for wrong role', ''
[ context 'when called with status active and origin local and permissions staff' do
[{ status: 'active', origin: 'local', permissions: 'staff' }, [:admin_account]], let(:params) { { status: 'active', origin: 'local', permissions: 'staff' } }
[{ 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 }
it "returns the correct accounts (#{expected_results.inspect})" do it 'returns the correct accounts' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(body_json_ids).to eq([admin_account.id])
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
end end
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 context 'with limit param' do
let(:params) { { limit: 1 } } let(:params) { { limit: 1 } }

View File

@ -22,6 +22,10 @@ RSpec.describe Api::V2::Filters::KeywordsController do
it 'returns http success' do it 'returns http success' do
get :index, params: { filter_id: filter.id } get :index, params: { filter_id: filter.id }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(body_as_json)
.to contain_exactly(
include(id: keyword.id.to_s)
)
end end
context "when trying to access another's user filters" do context "when trying to access another's user filters" do

View File

@ -22,6 +22,10 @@ RSpec.describe Api::V2::Filters::StatusesController do
it 'returns http success' do it 'returns http success' do
get :index, params: { filter_id: filter.id } get :index, params: { filter_id: filter.id }
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(body_as_json)
.to contain_exactly(
include(id: status_filter.id.to_s)
)
end end
context "when trying to access another's user filters" do context "when trying to access another's user filters" do