From a2c663c544ecd160ef33fbe63b88ff9bb35f1146 Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 10 Jul 2024 13:55:04 -0500 Subject: [PATCH] Finish update before enqueueing worker (#4358) * Complete super update before enqueueing worker * Expect id to be a string --- app/controllers/api/v1/aggregations_controller.rb | 5 ++--- spec/controllers/api/v1/aggregations_controller_spec.rb | 6 +++--- spec/workers/aggregation_completed_mailer_worker_spec.rb | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/aggregations_controller.rb b/app/controllers/api/v1/aggregations_controller.rb index c8209a316..97b0eddde 100644 --- a/app/controllers/api/v1/aggregations_controller.rb +++ b/app/controllers/api/v1/aggregations_controller.rb @@ -24,8 +24,7 @@ def create end def update - super do |agg| - AggregationCompletedMailerWorker.perform_async(agg.id) if update_params[:status] - end + super + AggregationCompletedMailerWorker.perform_async(params['id']) if update_params[:status] end end diff --git a/spec/controllers/api/v1/aggregations_controller_spec.rb b/spec/controllers/api/v1/aggregations_controller_spec.rb index 927fdb780..c7ff22875 100644 --- a/spec/controllers/api/v1/aggregations_controller_spec.rb +++ b/spec/controllers/api/v1/aggregations_controller_spec.rb @@ -111,14 +111,14 @@ context 'with the mailer worker' do before do default_request scopes: scopes, user_id: authorized_user.id - allow(AggregationCompletedMailerWorker).to receive(:perform_async).with(resource.id) + allow(AggregationCompletedMailerWorker).to receive(:perform_async).with(resource.id.to_s) end - let(:params) { update_params.merge(id: resource.id) } + let(:params) { update_params.merge(id: resource.id.to_s) } it 'calls the mailer worker' do put :update, params: params - expect(AggregationCompletedMailerWorker).to have_received(:perform_async).with(resource.id) + expect(AggregationCompletedMailerWorker).to have_received(:perform_async).with(resource.id.to_s) end it 'does not call the mailer if status is not an updated param' do diff --git a/spec/workers/aggregation_completed_mailer_worker_spec.rb b/spec/workers/aggregation_completed_mailer_worker_spec.rb index 4cce4c9fd..29d2c2238 100644 --- a/spec/workers/aggregation_completed_mailer_worker_spec.rb +++ b/spec/workers/aggregation_completed_mailer_worker_spec.rb @@ -6,7 +6,7 @@ let(:aggregation) { create(:aggregation) } it 'delivers the mail' do - expect { described_class.new.perform(aggregation.id) }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect { described_class.new.perform(aggregation.id.to_s) }.to change { ActionMailer::Base.deliveries.count }.by(1) end context 'with missing attributes' do