From 19c6cb82f63f44627fc38d586c0517b7b79fb9e9 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 10 Dec 2024 09:45:14 -0500 Subject: [PATCH] Add coverage for `Admin::DistributeTermsOfServiceNotificationWorker` class (#33245) --- ...rms_of_service_notification_worker_spec.rb | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/workers/admin/distribute_terms_of_service_notification_worker_spec.rb diff --git a/spec/workers/admin/distribute_terms_of_service_notification_worker_spec.rb b/spec/workers/admin/distribute_terms_of_service_notification_worker_spec.rb new file mode 100644 index 0000000000..27ddfb28bc --- /dev/null +++ b/spec/workers/admin/distribute_terms_of_service_notification_worker_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Admin::DistributeTermsOfServiceNotificationWorker do + let(:worker) { described_class.new } + + describe '#perform' do + context 'with missing record' do + it 'runs without error' do + expect { worker.perform(nil) }.to_not raise_error + end + end + + context 'with valid terms' do + let(:terms) { Fabricate(:terms_of_service) } + let!(:user) { Fabricate :user, confirmed_at: 3.days.ago } + + it 'sends the terms update via email', :inline_jobs do + emails = capture_emails { worker.perform(terms.id) } + + expect(emails.size) + .to eq(1) + expect(emails.first) + .to have_attributes( + to: [user.email], + subject: I18n.t('user_mailer.terms_of_service_changed.subject') + ) + end + end + end +end