Fix `RSpec/SubjectDeclaration` cop (#25312)

th-downstream
Matt Jankowski 1 year ago committed by GitHub
parent 226eaee2f2
commit d9e56ef7ba

@ -409,29 +409,6 @@ RSpec/StubbedMock:
- 'spec/lib/webfinger_resource_spec.rb' - 'spec/lib/webfinger_resource_spec.rb'
- 'spec/services/activitypub/process_collection_service_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: RSpec/SubjectStub:
Exclude: Exclude:
- 'spec/services/unallow_domain_service_spec.rb' - 'spec/services/unallow_domain_service_spec.rb'

@ -166,10 +166,11 @@ RSpec.describe Admin::DomainBlocksController do
end end
describe 'PUT #update' do describe 'PUT #update' do
let!(:remote_account) { Fabricate(:account, domain: 'example.com') } subject do
let(:subject) do
post :update, params: { :id => domain_block.id, :domain_block => { domain: 'example.com', severity: new_severity }, 'confirm' => '' } post :update, params: { :id => domain_block.id, :domain_block => { domain: 'example.com', severity: new_severity }, 'confirm' => '' }
end end
let!(:remote_account) { Fabricate(:account, domain: 'example.com') }
let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) } let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) }
before do before do

@ -4,11 +4,11 @@ require 'rails_helper'
RSpec.describe AccountMigration do RSpec.describe AccountMigration do
describe 'validations' do describe 'validations' do
subject { described_class.new(account: source_account, acct: target_acct) }
let(:source_account) { Fabricate(:account) } let(:source_account) { Fabricate(:account) }
let(:target_acct) { target_account.acct } let(:target_acct) { target_account.acct }
let(:subject) { described_class.new(account: source_account, acct: target_acct) }
context 'with valid properties' do context 'with valid properties' do
let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') } let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') }

@ -20,7 +20,9 @@ RSpec.describe Account do
end end
context 'when the account is of a local user' do 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 it 'creates a canonical domain block' do
subject.suspend! subject.suspend!

@ -7,7 +7,7 @@ describe RelationshipFilter do
describe '#results' do describe '#results' do
context 'when default params are used' do context 'when default params are used' do
let(:subject) do subject do
described_class.new(account, 'order' => 'active').results described_class.new(account, 'order' => 'active').results
end end

@ -93,7 +93,7 @@ RSpec.describe UserRole do
describe '#computed_permissions' do describe '#computed_permissions' do
context 'when the role is nobody' do context 'when the role is nobody' do
let(:subject) { described_class.nobody } subject { described_class.nobody }
it 'returns none' do it 'returns none' do
expect(subject.computed_permissions).to eq UserRole::Flags::NONE expect(subject.computed_permissions).to eq UserRole::Flags::NONE
@ -101,7 +101,7 @@ RSpec.describe UserRole do
end end
context 'when the role is everyone' do context 'when the role is everyone' do
let(:subject) { described_class.everyone } subject { described_class.everyone }
it 'returns permissions' do it 'returns permissions' do
expect(subject.computed_permissions).to eq subject.permissions expect(subject.computed_permissions).to eq subject.permissions

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe AccountModerationNotePolicy do RSpec.describe AccountModerationNotePolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe AccountPolicy do RSpec.describe AccountPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
let(:alice) { Fabricate(:account) } let(:alice) { Fabricate(:account) }

@ -4,8 +4,9 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe BackupPolicy do RSpec.describe BackupPolicy do
let(:subject) { described_class } subject { described_class }
let(:john) { Fabricate(:account) }
let(:john) { Fabricate(:account) }
permissions :create? do permissions :create? do
context 'when not user_signed_in?' do context 'when not user_signed_in?' do

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe CustomEmojiPolicy do RSpec.describe CustomEmojiPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe DomainBlockPolicy do RSpec.describe DomainBlockPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe EmailDomainBlockPolicy do RSpec.describe EmailDomainBlockPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe InstancePolicy do RSpec.describe InstancePolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe InvitePolicy do RSpec.describe InvitePolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:user).account } let(:john) { Fabricate(:user).account }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe RelayPolicy do RSpec.describe RelayPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe ReportNotePolicy do RSpec.describe ReportNotePolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe ReportPolicy do RSpec.describe ReportPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe SettingsPolicy do RSpec.describe SettingsPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe TagPolicy do RSpec.describe TagPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -4,7 +4,8 @@ require 'rails_helper'
require 'pundit/rspec' require 'pundit/rspec'
RSpec.describe UserPolicy do RSpec.describe UserPolicy do
let(:subject) { described_class } subject { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }

@ -113,11 +113,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end end
context 'when discovering many subdomains in a short timeframe' do context 'when discovering many subdomains in a short timeframe' do
before do subject do
stub_const 'ActivityPub::ProcessAccountService::SUBDOMAINS_RATELIMIT', 5
end
let(:subject) do
8.times do |i| 8.times do |i|
domain = "test#{i}.testdomain.com" domain = "test#{i}.testdomain.com"
json = { json = {
@ -129,6 +125,10 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end end
end end
before do
stub_const 'ActivityPub::ProcessAccountService::SUBDOMAINS_RATELIMIT', 5
end
it 'creates at least some accounts' do it 'creates at least some accounts' do
expect { subject }.to change { Account.remote.count }.by_at_least(2) expect { subject }.to change { Account.remote.count }.by_at_least(2)
end end

Loading…
Cancel
Save