Fix RSpec/ExpectChange cop (#25101)
This commit is contained in:
parent
1caa5ff39e
commit
d2e5430d4a
12 changed files with 24 additions and 41 deletions
|
@ -376,23 +376,6 @@ RSpec/EmptyExampleGroup:
|
||||||
RSpec/ExampleLength:
|
RSpec/ExampleLength:
|
||||||
Max: 22
|
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).
|
# This cop supports safe autocorrection (--autocorrect).
|
||||||
# Configuration parameters: EnforcedStyle.
|
# Configuration parameters: EnforcedStyle.
|
||||||
# SupportedStyles: implicit, each, example
|
# SupportedStyles: implicit, each, example
|
||||||
|
|
|
@ -19,7 +19,7 @@ RSpec.describe Admin::AccountModerationNotesController do
|
||||||
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test content' } } }
|
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: 'test content' } } }
|
||||||
|
|
||||||
it 'successfully creates a note' do
|
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)
|
expect(subject).to redirect_to admin_account_path(target_account.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ RSpec.describe Admin::AccountModerationNotesController do
|
||||||
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
|
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
|
||||||
|
|
||||||
it 'falls to create a note' do
|
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'
|
expect(subject).to render_template 'admin/accounts/show'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ RSpec.describe Admin::AccountModerationNotesController do
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
|
|
||||||
it 'destroys note' do
|
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)
|
expect(subject).to redirect_to admin_account_path(target_account.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,7 +42,7 @@ describe Admin::CustomEmojisController do
|
||||||
let(:params) { { shortcode: 'test', image: image } }
|
let(:params) { { shortcode: 'test', image: image } }
|
||||||
|
|
||||||
it 'creates custom emoji' do
|
it 'creates custom emoji' do
|
||||||
expect { subject }.to change { CustomEmoji.count }.by(1)
|
expect { subject }.to change(CustomEmoji, :count).by(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe Admin::InvitesController do
|
||||||
subject { post :create, params: { invite: { max_uses: '10', expires_in: 1800 } } }
|
subject { post :create, params: { invite: { max_uses: '10', expires_in: 1800 } } }
|
||||||
|
|
||||||
it 'succeeds to create a invite' do
|
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(subject).to redirect_to admin_invites_path
|
||||||
expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
|
expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@ describe Admin::ReportNotesController do
|
||||||
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } }
|
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } }
|
||||||
|
|
||||||
it 'creates a report note and resolves report' do
|
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(report.reload).to be_action_taken
|
||||||
expect(subject).to redirect_to admin_reports_path
|
expect(subject).to redirect_to admin_reports_path
|
||||||
end
|
end
|
||||||
|
@ -35,7 +35,7 @@ describe Admin::ReportNotesController do
|
||||||
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
|
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
|
||||||
|
|
||||||
it 'creates a report note and does not resolve report' do
|
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(report.reload).to_not be_action_taken
|
||||||
expect(subject).to redirect_to admin_report_path(report)
|
expect(subject).to redirect_to admin_report_path(report)
|
||||||
end
|
end
|
||||||
|
@ -50,7 +50,7 @@ describe Admin::ReportNotesController do
|
||||||
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } }
|
let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } }
|
||||||
|
|
||||||
it 'creates a report note and unresolves report' do
|
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(report.reload).to_not be_action_taken
|
||||||
expect(subject).to redirect_to admin_report_path(report)
|
expect(subject).to redirect_to admin_report_path(report)
|
||||||
end
|
end
|
||||||
|
@ -60,7 +60,7 @@ describe Admin::ReportNotesController do
|
||||||
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
|
let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
|
||||||
|
|
||||||
it 'creates a report note and does not unresolve report' do
|
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(report.reload).to be_action_taken
|
||||||
expect(subject).to redirect_to admin_report_path(report)
|
expect(subject).to redirect_to admin_report_path(report)
|
||||||
end
|
end
|
||||||
|
@ -85,7 +85,7 @@ describe Admin::ReportNotesController do
|
||||||
let!(:report_note) { Fabricate(:report_note) }
|
let!(:report_note) { Fabricate(:report_note) }
|
||||||
|
|
||||||
it 'deletes note' do
|
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)
|
expect(subject).to redirect_to admin_report_path(report_note.report)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ RSpec.describe AccountableConcern do
|
||||||
it 'creates Admin::ActionLog' do
|
it 'creates Admin::ActionLog' do
|
||||||
expect do
|
expect do
|
||||||
hoge.log_action(:create, target)
|
hoge.log_action(:create, target)
|
||||||
end.to change { Admin::ActionLog.count }.by(1)
|
end.to change(Admin::ActionLog, :count).by(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,7 +52,7 @@ describe InvitesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'succeeds to create a invite' do
|
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(subject).to redirect_to invites_path
|
||||||
expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
|
expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
|
||||||
end
|
end
|
||||||
|
|
|
@ -134,7 +134,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not change webauthn_id' do
|
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
|
end
|
||||||
|
|
||||||
it 'includes existing credentials in list of excluded credentials' do
|
it 'includes existing credentials in list of excluded credentials' do
|
||||||
|
@ -238,7 +238,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
post :create, params: { credential: new_webauthn_credential, nickname: nickname }
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ RSpec.describe Admin::AccountAction do
|
||||||
it 'creates Admin::ActionLog' do
|
it 'creates Admin::ActionLog' do
|
||||||
expect do
|
expect do
|
||||||
subject
|
subject
|
||||||
end.to change { Admin::ActionLog.count }.by 1
|
end.to change(Admin::ActionLog, :count).by 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls process_email!' do
|
it 'calls process_email!' do
|
||||||
|
|
|
@ -26,7 +26,7 @@ RSpec.describe SuspendAccountService, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not change the “suspended” flag' do
|
it 'does not change the “suspended” flag' do
|
||||||
expect { subject }.to_not change { account.suspended? }
|
expect { subject }.to_not change(account, :suspended?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ RSpec.describe UnsuspendAccountService, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not change the “suspended” flag' do
|
it 'does not change the “suspended” flag' do
|
||||||
expect { subject }.to_not change { account.suspended? }
|
expect { subject }.to_not change(account, :suspended?)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples 'with common context' do
|
include_examples 'with common context' do
|
||||||
|
@ -86,7 +86,7 @@ RSpec.describe UnsuspendAccountService, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not change the “suspended” flag' do
|
it 'does not change the “suspended” flag' do
|
||||||
expect { subject }.to_not change { account.suspended? }
|
expect { subject }.to_not change(account, :suspended?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ RSpec.describe UnsuspendAccountService, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'marks account as suspended' do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
|
||||||
describe '#perform' do
|
describe '#perform' do
|
||||||
context 'when the budget is lower than the number of toots to delete' 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
|
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
|
end
|
||||||
|
|
||||||
it 'does not delete from accounts with no cleanup policy' do
|
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
|
it 'eventually deletes every deletable toot given enough runs' do
|
||||||
stub_const 'Scheduler::AccountsStatusesCleanupScheduler::MAX_BUDGET', 4
|
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
|
end
|
||||||
|
|
||||||
it 'correctly round-trips between users across several runs' do
|
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
|
stub_const 'Scheduler::AccountsStatusesCleanupScheduler::PER_ACCOUNT_BUDGET', 2
|
||||||
|
|
||||||
expect { 3.times { subject.perform } }
|
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 { account1.statuses.count }
|
||||||
.and change { account3.statuses.count }
|
.and change { account3.statuses.count }
|
||||||
.and change { account5.statuses.count }
|
.and change { account5.statuses.count }
|
||||||
|
@ -140,7 +140,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
|
||||||
|
|
||||||
it 'correctly handles looping in a single run' do
|
it 'correctly handles looping in a single run' do
|
||||||
expect(subject.compute_budget).to eq(400)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ describe Scheduler::AccountsStatusesCleanupScheduler do
|
||||||
|
|
||||||
it 'does not get stuck' do
|
it 'does not get stuck' do
|
||||||
expect(subject.compute_budget).to eq(400)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue