Combine repeated subjects in `models/user` spec (#28937)

This commit is contained in:
Matt Jankowski 2024-01-26 11:22:44 -05:00 committed by GitHub
parent 2f8656334d
commit 6d35a77c92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 24 deletions

View File

@ -187,12 +187,9 @@ RSpec.describe User do
context 'when the user is already confirmed' do context 'when the user is already confirmed' do
let!(:user) { Fabricate(:user, confirmed_at: Time.now.utc, approved: true, unconfirmed_email: new_email) } 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) 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) expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id)
end end
end end
@ -206,12 +203,9 @@ RSpec.describe User do
user.approve! user.approve!
end 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) 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 expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once
end end
end end
@ -221,12 +215,9 @@ RSpec.describe User do
Setting.registrations_mode = 'open' Setting.registrations_mode = 'open'
end 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) 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 expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once
end end
end end
@ -236,12 +227,9 @@ RSpec.describe User do
Setting.registrations_mode = 'approved' Setting.registrations_mode = 'approved'
end 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) 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) expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id)
end end
end end
@ -259,12 +247,9 @@ RSpec.describe User do
context 'when the user is already confirmed' do context 'when the user is already confirmed' do
let(:user) { Fabricate(:user, confirmed_at: Time.now.utc, approved: false) } 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) 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 expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once
end end
end end
@ -272,12 +257,9 @@ RSpec.describe User do
context 'when the user is not confirmed' do context 'when the user is not confirmed' do
let(:user) { Fabricate(:user, confirmed_at: nil, approved: false) } 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) 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) expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id)
end end
end end