From 6d35a77c9226881c1d554566aca120e330004df1 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 26 Jan 2024 11:22:44 -0500 Subject: [PATCH] Combine repeated subjects in `models/user` spec (#28937) --- spec/models/user_spec.rb | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 213022e830..5ac41c0ff1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -187,12 +187,9 @@ RSpec.describe User do context 'when the user is already confirmed' do let!(:user) { Fabricate(:user, confirmed_at: Time.now.utc, approved: true, unconfirmed_email: new_email) } - it 'sets email to unconfirmed_email' do + it 'sets email to unconfirmed_email and does not trigger web hook' do expect { subject }.to change { user.reload.email }.to(new_email) - end - it 'does not trigger the account.approved Web Hook' do - subject expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id) end end @@ -206,12 +203,9 @@ RSpec.describe User do user.approve! end - it 'sets email to unconfirmed_email' do + it 'sets email to unconfirmed_email and triggers `account.approved` web hook' do expect { subject }.to change { user.reload.email }.to(new_email) - end - it 'triggers the account.approved Web Hook' do - user.confirm expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once end end @@ -221,12 +215,9 @@ RSpec.describe User do Setting.registrations_mode = 'open' end - it 'sets email to unconfirmed_email' do + it 'sets email to unconfirmed_email and triggers `account.approved` web hook' do expect { subject }.to change { user.reload.email }.to(new_email) - end - it 'triggers the account.approved Web Hook' do - user.confirm expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once end end @@ -236,12 +227,9 @@ RSpec.describe User do Setting.registrations_mode = 'approved' end - it 'sets email to unconfirmed_email' do + it 'sets email to unconfirmed_email and does not trigger web hook' do expect { subject }.to change { user.reload.email }.to(new_email) - end - it 'does not trigger the account.approved Web Hook' do - subject expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id) end end @@ -259,12 +247,9 @@ RSpec.describe User do context 'when the user is already confirmed' do let(:user) { Fabricate(:user, confirmed_at: Time.now.utc, approved: false) } - it 'sets the approved flag' do + it 'sets the approved flag and triggers `account.approved` web hook' do expect { subject }.to change { user.reload.approved? }.to(true) - end - it 'triggers the account.approved Web Hook' do - subject expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once end end @@ -272,12 +257,9 @@ RSpec.describe User do context 'when the user is not confirmed' do let(:user) { Fabricate(:user, confirmed_at: nil, approved: false) } - it 'sets the approved flag' do + it 'sets the approved flag and does not trigger web hook' do expect { subject }.to change { user.reload.approved? }.to(true) - end - it 'does not trigger the account.approved Web Hook' do - subject expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id) end end