1
0
mirror of https://github.com/whippyshou/mastodon synced 2024-11-27 22:38:35 +09:00

Fix RSpec/ExpectChange cop (#25101)

This commit is contained in:
Matt Jankowski 2023-05-24 05:23:40 -04:00 committed by GitHub
parent 1caa5ff39e
commit d2e5430d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 24 additions and 41 deletions

View File

@ -376,23 +376,6 @@ RSpec/EmptyExampleGroup:
RSpec/ExampleLength:
Max: 22
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: method_call, block
RSpec/ExpectChange:
Exclude:
- 'spec/controllers/admin/account_moderation_notes_controller_spec.rb'
- 'spec/controllers/admin/custom_emojis_controller_spec.rb'
- 'spec/controllers/admin/invites_controller_spec.rb'
- 'spec/controllers/admin/report_notes_controller_spec.rb'
- 'spec/controllers/concerns/accountable_concern_spec.rb'
- 'spec/controllers/invites_controller_spec.rb'
- 'spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb'
- 'spec/models/admin/account_action_spec.rb'
- 'spec/services/suspend_account_service_spec.rb'
- 'spec/services/unsuspend_account_service_spec.rb'
- 'spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb'
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, each, example

View File

@ -19,7 +19,7 @@ RSpec.describe Admin::AccountModerationNotesController do
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test content' } } }
it 'successfully creates a note' do
expect { subject }.to change { AccountModerationNote.count }.by(1)
expect { subject }.to change(AccountModerationNote, :count).by(1)
expect(subject).to redirect_to admin_account_path(target_account.id)
end
end
@ -28,7 +28,7 @@ RSpec.describe Admin::AccountModerationNotesController do
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
it 'falls to create a note' do
expect { subject }.to_not change { AccountModerationNote.count }
expect { subject }.to_not change(AccountModerationNote, :count)
expect(subject).to render_template 'admin/accounts/show'
end
end
@ -41,7 +41,7 @@ RSpec.describe Admin::AccountModerationNotesController do
let(:account) { Fabricate(:account) }
it 'destroys note' do
expect { subject }.to change { AccountModerationNote.count }.by(-1)
expect { subject }.to change(AccountModerationNote, :count).by(-1)
expect(subject).to redirect_to admin_account_path(target_account.id)
end
end

View File

@ -42,7 +42,7 @@ describe Admin::CustomEmojisController do
let(:params) { { shortcode: 'test', image: image } }
it 'creates custom emoji' do
expect { subject }.to change { CustomEmoji.count }.by(1)
expect { subject }.to change(CustomEmoji, :count).by(1)
end
end

View File

@ -26,7 +26,7 @@ describe Admin::InvitesController do
subject { post :create, params: { invite: { max_uses: '10', expires_in: 1800 } } }
it 'succeeds to create a invite' do
expect { subject }.to change { Invite.count }.by(1)
expect { subject }.to change(Invite, :count).by(1)
expect(subject).to redirect_to admin_invites_path
expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
end

View File

@ -25,7 +25,7 @@ describe Admin::ReportNotesController do
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } }
it 'creates a report note and resolves report' do
expect { subject }.to change { ReportNote.count }.by(1)
expect { subject }.to change(ReportNote, :count).by(1)
expect(report.reload).to be_action_taken
expect(subject).to redirect_to admin_reports_path
end
@ -35,7 +35,7 @@ describe Admin::ReportNotesController do
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
it 'creates a report note and does not resolve report' do
expect { subject }.to change { ReportNote.count }.by(1)
expect { subject }.to change(ReportNote, :count).by(1)
expect(report.reload).to_not be_action_taken
expect(subject).to redirect_to admin_report_path(report)
end
@ -50,7 +50,7 @@ describe Admin::ReportNotesController do
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } }
it 'creates a report note and unresolves report' do
expect { subject }.to change { ReportNote.count }.by(1)
expect { subject }.to change(ReportNote, :count).by(1)
expect(report.reload).to_not be_action_taken
expect(subject).to redirect_to admin_report_path(report)
end
@ -60,7 +60,7 @@ describe Admin::ReportNotesController do
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
it 'creates a report note and does not unresolve report' do
expect { subject }.to change { ReportNote.count }.by(1)
expect { subject }.to change(ReportNote, :count).by(1)
expect(report.reload).to be_action_taken
expect(subject).to redirect_to admin_report_path(report)
end
@ -85,7 +85,7 @@ describe Admin::ReportNotesController do
let!(:report_note) { Fabricate(:report_note) }
it 'deletes note' do
expect { subject }.to change { ReportNote.count }.by(-1)
expect { subject }.to change(ReportNote, :count).by(-1)
expect(subject).to redirect_to admin_report_path(report_note.report)
end
end

View File

@ -22,7 +22,7 @@ RSpec.describe AccountableConcern do
it 'creates Admin::ActionLog' do
expect do
hoge.log_action(:create, target)
end.to change { Admin::ActionLog.count }.by(1)
end.to change(Admin::ActionLog, :count).by(1)
end
end
end

View File

@ -52,7 +52,7 @@ describe InvitesController do
end
it 'succeeds to create a invite' do
expect { subject }.to change { Invite.count }.by(1)
expect { subject }.to change(Invite, :count).by(1)
expect(subject).to redirect_to invites_path
expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
end

View File

@ -134,7 +134,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
end
it 'does not change webauthn_id' do
expect { get :options }.to_not change { user.webauthn_id }
expect { get :options }.to_not change(user, :webauthn_id)
end
it 'includes existing credentials in list of excluded credentials' do
@ -238,7 +238,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
expect do
post :create, params: { credential: new_webauthn_credential, nickname: nickname }
end.to_not change { user.webauthn_id }
end.to_not change(user, :webauthn_id)
end
end

View File

@ -58,7 +58,7 @@ RSpec.describe Admin::AccountAction do
it 'creates Admin::ActionLog' do
expect do
subject
end.to change { Admin::ActionLog.count }.by 1
end.to change(Admin::ActionLog, :count).by 1
end
it 'calls process_email!' do

View File

@ -26,7 +26,7 @@ RSpec.describe SuspendAccountService, type: :service do
end
it 'does not change the “suspended” flag' do
expect { subject }.to_not change { account.suspended? }
expect { subject }.to_not change(account, :suspended?)
end
end

View File

@ -33,7 +33,7 @@ RSpec.describe UnsuspendAccountService, type: :service do
end
it 'does not change the “suspended” flag' do
expect { subject }.to_not change { account.suspended? }
expect { subject }.to_not change(account, :suspended?)
end
include_examples 'with common context' do
@ -86,7 +86,7 @@ RSpec.describe UnsuspendAccountService, type: :service do
end
it 'does not change the “suspended” flag' do
expect { subject }.to_not change { account.suspended? }
expect { subject }.to_not change(account, :suspended?)
end
end
@ -110,7 +110,7 @@ RSpec.describe UnsuspendAccountService, type: :service do
end
it 'marks account as suspended' do
expect { subject }.to change { account.suspended? }.from(false).to(true)
expect { subject }.to change(account, :suspended?).from(false).to(true)
end
end

View File

@ -103,7 +103,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
describe '#perform' do
context 'when the budget is lower than the number of toots to delete' do
it 'deletes as many statuses as the given budget' do
expect { subject.perform }.to change { Status.count }.by(-subject.compute_budget)
expect { subject.perform }.to change(Status, :count).by(-subject.compute_budget)
end
it 'does not delete from accounts with no cleanup policy' do
@ -117,7 +117,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
it 'eventually deletes every deletable toot given enough runs' do
stub_const 'Scheduler::AccountsStatusesCleanupScheduler::MAX_BUDGET', 4
expect { 10.times { subject.perform } }.to change { Status.count }.by(-30)
expect { 10.times { subject.perform } }.to change(Status, :count).by(-30)
end
it 'correctly round-trips between users across several runs' do
@ -125,7 +125,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
stub_const 'Scheduler::AccountsStatusesCleanupScheduler::PER_ACCOUNT_BUDGET', 2
expect { 3.times { subject.perform } }
.to change { Status.count }.by(-3 * 3)
.to change(Status, :count).by(-3 * 3)
.and change { account1.statuses.count }
.and change { account3.statuses.count }
.and change { account5.statuses.count }
@ -140,7 +140,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
it 'correctly handles looping in a single run' do
expect(subject.compute_budget).to eq(400)
expect { subject.perform }.to change { Status.count }.by(-30)
expect { subject.perform }.to change(Status, :count).by(-30)
end
end
@ -154,7 +154,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
it 'does not get stuck' do
expect(subject.compute_budget).to eq(400)
expect { subject.perform }.to_not change { Status.count }
expect { subject.perform }.to_not change(Status, :count)
end
end
end