Skip to content

Commit

Permalink
Finish update before enqueueing worker (#4358)
Browse files Browse the repository at this point in the history
* Complete super update before enqueueing worker

* Expect id to be a string
  • Loading branch information
zwolf authored Jul 10, 2024
1 parent 115e6de commit a2c663c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions app/controllers/api/v1/aggregations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/controllers/api/v1/aggregations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/workers/aggregation_completed_mailer_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a2c663c

Please sign in to comment.