From a610a02d4f19e6c2b218d9792f0dbf272b1bbda3 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 11 May 2023 04:32:09 -0400 Subject: [PATCH] Fix RSpec/ScatteredSetup cop (#24848) --- .rubocop_todo.yml | 8 -------- .../followers_synchronizations_controller_spec.rb | 2 -- .../activitypub/outboxes_controller_spec.rb | 2 -- .../admin/disputes/appeals_controller_spec.rb | 10 +++++----- spec/controllers/auth/registrations_controller_spec.rb | 4 ++-- .../activitypub/process_account_service_spec.rb | 6 ++---- 6 files changed, 9 insertions(+), 23 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 77b8e95f8..a83fec8ae 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -648,14 +648,6 @@ RSpec/RepeatedExampleGroupDescription: - 'spec/controllers/admin/reports/actions_controller_spec.rb' - 'spec/policies/report_note_policy_spec.rb' -RSpec/ScatteredSetup: - Exclude: - - 'spec/controllers/activitypub/followers_synchronizations_controller_spec.rb' - - 'spec/controllers/activitypub/outboxes_controller_spec.rb' - - 'spec/controllers/admin/disputes/appeals_controller_spec.rb' - - 'spec/controllers/auth/registrations_controller_spec.rb' - - 'spec/services/activitypub/process_account_service_spec.rb' - # This cop supports safe autocorrection (--autocorrect). RSpec/SharedContext: Exclude: diff --git a/spec/controllers/activitypub/followers_synchronizations_controller_spec.rb b/spec/controllers/activitypub/followers_synchronizations_controller_spec.rb index 8fcce165b..e544585ec 100644 --- a/spec/controllers/activitypub/followers_synchronizations_controller_spec.rb +++ b/spec/controllers/activitypub/followers_synchronizations_controller_spec.rb @@ -14,9 +14,7 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController do follower_2.follow!(account) follower_3.follow!(account) follower_4.follow!(account) - end - before do allow(controller).to receive(:signed_request_actor).and_return(remote_account) end diff --git a/spec/controllers/activitypub/outboxes_controller_spec.rb b/spec/controllers/activitypub/outboxes_controller_spec.rb index 8823d9fe7..6946fdfcf 100644 --- a/spec/controllers/activitypub/outboxes_controller_spec.rb +++ b/spec/controllers/activitypub/outboxes_controller_spec.rb @@ -27,9 +27,7 @@ RSpec.describe ActivityPub::OutboxesController do Fabricate(:status, account: account, visibility: :private) Fabricate(:status, account: account, visibility: :direct) Fabricate(:status, account: account, visibility: :limited) - end - before do allow(controller).to receive(:signed_request_actor).and_return(remote_account) end diff --git a/spec/controllers/admin/disputes/appeals_controller_spec.rb b/spec/controllers/admin/disputes/appeals_controller_spec.rb index 371c4f483..99b19298c 100644 --- a/spec/controllers/admin/disputes/appeals_controller_spec.rb +++ b/spec/controllers/admin/disputes/appeals_controller_spec.rb @@ -5,16 +5,16 @@ require 'rails_helper' RSpec.describe Admin::Disputes::AppealsController do render_views - before { sign_in current_user, scope: :user } + before do + sign_in current_user, scope: :user + + target_account.suspend! + end let(:target_account) { Fabricate(:account) } let(:strike) { Fabricate(:account_warning, target_account: target_account, action: :suspend) } let(:appeal) { Fabricate(:appeal, strike: strike, account: target_account) } - before do - target_account.suspend! - end - describe 'POST #approve' do let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } diff --git a/spec/controllers/auth/registrations_controller_spec.rb b/spec/controllers/auth/registrations_controller_spec.rb index ad8465e2a..42b2606ad 100644 --- a/spec/controllers/auth/registrations_controller_spec.rb +++ b/spec/controllers/auth/registrations_controller_spec.rb @@ -101,6 +101,8 @@ RSpec.describe Auth::RegistrationsController do before do session[:registration_form_time] = 5.seconds.ago + + request.env['devise.mapping'] = Devise.mappings[:user] end around do |example| @@ -109,8 +111,6 @@ RSpec.describe Auth::RegistrationsController do end end - before { request.env['devise.mapping'] = Devise.mappings[:user] } - context do subject do Setting.registrations_mode = 'open' diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index ffbc51b64..4c5e6b6cc 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -139,10 +139,6 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do end context 'when Accounts referencing other accounts' do - before do - stub_const 'ActivityPub::ProcessAccountService::DISCOVERIES_PER_REQUEST', 5 - end - let(:payload) do { '@context': ['https://www.w3.org/ns/activitystreams'], @@ -155,6 +151,8 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do end before do + stub_const 'ActivityPub::ProcessAccountService::DISCOVERIES_PER_REQUEST', 5 + 8.times do |i| actor_json = { '@context': ['https://www.w3.org/ns/activitystreams'],