Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RSpec/SubjectDeclaration cop #25312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 0 additions & 23 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/admin/domain_blocks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@
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
Expand Down
4 changes: 2 additions & 2 deletions spec/models/account_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

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') }

Expand Down
4 changes: 3 additions & 1 deletion spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
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!
Expand Down
2 changes: 1 addition & 1 deletion spec/models/relationship_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

Expand Down
4 changes: 2 additions & 2 deletions spec/models/user_role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@

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
end
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
Expand Down
3 changes: 2 additions & 1 deletion spec/policies/account_moderation_note_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/account_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }
Expand Down
5 changes: 3 additions & 2 deletions spec/policies/backup_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
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
Expand Down
3 changes: 2 additions & 1 deletion spec/policies/custom_emoji_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/domain_block_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/email_domain_block_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/instance_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/invite_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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 }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/relay_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/report_note_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/report_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/settings_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/tag_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
3 changes: 2 additions & 1 deletion spec/policies/user_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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) }

Expand Down
10 changes: 5 additions & 5 deletions spec/services/activitypub/process_account_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@
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 = {
Expand All @@ -129,6 +125,10 @@
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
Expand Down