From c75df62cccd5c1d24e88774ac10803d2903d97a2 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 12 Jul 2023 03:49:33 -0400 Subject: [PATCH] Fix `RSpec/SubjectDeclaration` cop (#25312) --- .rubocop_todo.yml | 23 ------------------- .../admin/domain_blocks_controller_spec.rb | 5 ++-- spec/models/account_migration_spec.rb | 4 ++-- spec/models/account_spec.rb | 4 +++- spec/models/relationship_filter_spec.rb | 2 +- spec/models/user_role_spec.rb | 4 ++-- .../account_moderation_note_policy_spec.rb | 3 ++- spec/policies/account_policy_spec.rb | 3 ++- spec/policies/backup_policy_spec.rb | 5 ++-- spec/policies/custom_emoji_policy_spec.rb | 3 ++- spec/policies/domain_block_policy_spec.rb | 3 ++- .../email_domain_block_policy_spec.rb | 3 ++- spec/policies/instance_policy_spec.rb | 3 ++- spec/policies/invite_policy_spec.rb | 3 ++- spec/policies/relay_policy_spec.rb | 3 ++- spec/policies/report_note_policy_spec.rb | 3 ++- spec/policies/report_policy_spec.rb | 3 ++- spec/policies/settings_policy_spec.rb | 3 ++- spec/policies/tag_policy_spec.rb | 3 ++- spec/policies/user_policy_spec.rb | 3 ++- .../process_account_service_spec.rb | 10 ++++---- 21 files changed, 45 insertions(+), 51 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9b74778b0..9938916fc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -409,29 +409,6 @@ RSpec/StubbedMock: - 'spec/lib/webfinger_resource_spec.rb' - 'spec/services/activitypub/process_collection_service_spec.rb' -RSpec/SubjectDeclaration: - Exclude: - - 'spec/controllers/admin/domain_blocks_controller_spec.rb' - - 'spec/models/account_migration_spec.rb' - - 'spec/models/account_spec.rb' - - 'spec/models/relationship_filter_spec.rb' - - 'spec/models/user_role_spec.rb' - - 'spec/policies/account_moderation_note_policy_spec.rb' - - 'spec/policies/account_policy_spec.rb' - - 'spec/policies/backup_policy_spec.rb' - - 'spec/policies/custom_emoji_policy_spec.rb' - - 'spec/policies/domain_block_policy_spec.rb' - - 'spec/policies/email_domain_block_policy_spec.rb' - - 'spec/policies/instance_policy_spec.rb' - - 'spec/policies/invite_policy_spec.rb' - - 'spec/policies/relay_policy_spec.rb' - - 'spec/policies/report_note_policy_spec.rb' - - 'spec/policies/report_policy_spec.rb' - - 'spec/policies/settings_policy_spec.rb' - - 'spec/policies/tag_policy_spec.rb' - - 'spec/policies/user_policy_spec.rb' - - 'spec/services/activitypub/process_account_service_spec.rb' - RSpec/SubjectStub: Exclude: - 'spec/services/unallow_domain_service_spec.rb' diff --git a/spec/controllers/admin/domain_blocks_controller_spec.rb b/spec/controllers/admin/domain_blocks_controller_spec.rb index fb7fb2957..9be55906e 100644 --- a/spec/controllers/admin/domain_blocks_controller_spec.rb +++ b/spec/controllers/admin/domain_blocks_controller_spec.rb @@ -166,10 +166,11 @@ RSpec.describe Admin::DomainBlocksController do end describe 'PUT #update' do - let!(:remote_account) { Fabricate(:account, domain: 'example.com') } - let(:subject) do + subject do post :update, params: { :id => domain_block.id, :domain_block => { domain: 'example.com', severity: new_severity }, 'confirm' => '' } end + + let!(:remote_account) { Fabricate(:account, domain: 'example.com') } let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) } before do diff --git a/spec/models/account_migration_spec.rb b/spec/models/account_migration_spec.rb index f4544740b..1f32c6082 100644 --- a/spec/models/account_migration_spec.rb +++ b/spec/models/account_migration_spec.rb @@ -4,11 +4,11 @@ require 'rails_helper' RSpec.describe AccountMigration do describe 'validations' do + subject { described_class.new(account: source_account, acct: target_acct) } + let(:source_account) { Fabricate(:account) } let(:target_acct) { target_account.acct } - let(:subject) { described_class.new(account: source_account, acct: target_acct) } - context 'with valid properties' do let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') } diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 7cd914774..d473a819e 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -20,7 +20,9 @@ RSpec.describe Account do end context 'when the account is of a local user' do - let!(:subject) { Fabricate(:user, email: 'foo+bar@domain.org').account } + subject { local_user_account } + + let!(:local_user_account) { Fabricate(:user, email: 'foo+bar@domain.org').account } it 'creates a canonical domain block' do subject.suspend! diff --git a/spec/models/relationship_filter_spec.rb b/spec/models/relationship_filter_spec.rb index b3e855c12..ac3188577 100644 --- a/spec/models/relationship_filter_spec.rb +++ b/spec/models/relationship_filter_spec.rb @@ -7,7 +7,7 @@ describe RelationshipFilter do describe '#results' do context 'when default params are used' do - let(:subject) do + subject do described_class.new(account, 'order' => 'active').results end diff --git a/spec/models/user_role_spec.rb b/spec/models/user_role_spec.rb index 27b967414..f7cfe9bb0 100644 --- a/spec/models/user_role_spec.rb +++ b/spec/models/user_role_spec.rb @@ -93,7 +93,7 @@ RSpec.describe UserRole do describe '#computed_permissions' do context 'when the role is nobody' do - let(:subject) { described_class.nobody } + subject { described_class.nobody } it 'returns none' do expect(subject.computed_permissions).to eq UserRole::Flags::NONE @@ -101,7 +101,7 @@ RSpec.describe UserRole do end context 'when the role is everyone' do - let(:subject) { described_class.everyone } + subject { described_class.everyone } it 'returns permissions' do expect(subject.computed_permissions).to eq subject.permissions diff --git a/spec/policies/account_moderation_note_policy_spec.rb b/spec/policies/account_moderation_note_policy_spec.rb index 90abdfea7..8c37acc39 100644 --- a/spec/policies/account_moderation_note_policy_spec.rb +++ b/spec/policies/account_moderation_note_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe AccountModerationNotePolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/account_policy_spec.rb b/spec/policies/account_policy_spec.rb index 9f4e94a6c..d7a21d8e3 100644 --- a/spec/policies/account_policy_spec.rb +++ b/spec/policies/account_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe AccountPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } let(:alice) { Fabricate(:account) } diff --git a/spec/policies/backup_policy_spec.rb b/spec/policies/backup_policy_spec.rb index 488d48f52..28cb65d78 100644 --- a/spec/policies/backup_policy_spec.rb +++ b/spec/policies/backup_policy_spec.rb @@ -4,8 +4,9 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe BackupPolicy do - let(:subject) { described_class } - let(:john) { Fabricate(:account) } + subject { described_class } + + let(:john) { Fabricate(:account) } permissions :create? do context 'when not user_signed_in?' do diff --git a/spec/policies/custom_emoji_policy_spec.rb b/spec/policies/custom_emoji_policy_spec.rb index cf7e7d924..cb869c7d9 100644 --- a/spec/policies/custom_emoji_policy_spec.rb +++ b/spec/policies/custom_emoji_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe CustomEmojiPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/domain_block_policy_spec.rb b/spec/policies/domain_block_policy_spec.rb index e254e2cf4..4c89f3f37 100644 --- a/spec/policies/domain_block_policy_spec.rb +++ b/spec/policies/domain_block_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe DomainBlockPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/email_domain_block_policy_spec.rb b/spec/policies/email_domain_block_policy_spec.rb index 6e57b1372..7ecff4be4 100644 --- a/spec/policies/email_domain_block_policy_spec.rb +++ b/spec/policies/email_domain_block_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe EmailDomainBlockPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/instance_policy_spec.rb b/spec/policies/instance_policy_spec.rb index 3e047bbe9..a0d9a008b 100644 --- a/spec/policies/instance_policy_spec.rb +++ b/spec/policies/instance_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe InstancePolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/invite_policy_spec.rb b/spec/policies/invite_policy_spec.rb index 50a312f44..cbe3735d8 100644 --- a/spec/policies/invite_policy_spec.rb +++ b/spec/policies/invite_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe InvitePolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:user).account } diff --git a/spec/policies/relay_policy_spec.rb b/spec/policies/relay_policy_spec.rb index 0d479e0ca..29ba02c26 100644 --- a/spec/policies/relay_policy_spec.rb +++ b/spec/policies/relay_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe RelayPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/report_note_policy_spec.rb b/spec/policies/report_note_policy_spec.rb index a657fce4b..b40a87888 100644 --- a/spec/policies/report_note_policy_spec.rb +++ b/spec/policies/report_note_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe ReportNotePolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/report_policy_spec.rb b/spec/policies/report_policy_spec.rb index 8f2533fa6..4fc417807 100644 --- a/spec/policies/report_policy_spec.rb +++ b/spec/policies/report_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe ReportPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/settings_policy_spec.rb b/spec/policies/settings_policy_spec.rb index 576bfa4ab..4a9931490 100644 --- a/spec/policies/settings_policy_spec.rb +++ b/spec/policies/settings_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe SettingsPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/tag_policy_spec.rb b/spec/policies/tag_policy_spec.rb index 7791cde15..35da3cc62 100644 --- a/spec/policies/tag_policy_spec.rb +++ b/spec/policies/tag_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe TagPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/policies/user_policy_spec.rb b/spec/policies/user_policy_spec.rb index 384119f25..fa476a9fc 100644 --- a/spec/policies/user_policy_spec.rb +++ b/spec/policies/user_policy_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' require 'pundit/rspec' RSpec.describe UserPolicy do - let(:subject) { described_class } + subject { described_class } + let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:john) { Fabricate(:account) } diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index db454d7ad..c02a0800a 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -113,11 +113,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do end context 'when discovering many subdomains in a short timeframe' do - before do - stub_const 'ActivityPub::ProcessAccountService::SUBDOMAINS_RATELIMIT', 5 - end - - let(:subject) do + subject do 8.times do |i| domain = "test#{i}.testdomain.com" json = { @@ -129,6 +125,10 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do end end + before do + stub_const 'ActivityPub::ProcessAccountService::SUBDOMAINS_RATELIMIT', 5 + end + it 'creates at least some accounts' do expect { subject }.to change { Account.remote.count }.by_at_least(2) end