diff --git a/app/controllers/contest_instances_controller.rb b/app/controllers/contest_instances_controller.rb index 4233ba06..6b46946e 100644 --- a/app/controllers/contest_instances_controller.rb +++ b/app/controllers/contest_instances_controller.rb @@ -131,7 +131,8 @@ def send_round_results # Send an email for each entry entries.each do |entry| - ResultsMailer.entry_evaluation_notification(entry, judging_round).deliver_later + mail = ResultsMailer.entry_evaluation_notification(entry, judging_round) + mail.deliver_later email_count += 1 end diff --git a/spec/controllers/contest_instances_controller_spec.rb b/spec/controllers/contest_instances_controller_spec.rb index afaf97f6..8b19b123 100644 --- a/spec/controllers/contest_instances_controller_spec.rb +++ b/spec/controllers/contest_instances_controller_spec.rb @@ -95,11 +95,26 @@ # Configure ActiveJob to use inline adapter for testing ActiveJob::Base.queue_adapter = :inline + + # Mock the mailer to return a proper mail object + allow(ResultsMailer).to receive(:entry_evaluation_notification).and_wrap_original do |original_method, *args| + mail = original_method.call(*args) + allow(mail).to receive(:deliver_now) do + ActionMailer::Base.deliveries << mail + true + end + allow(mail).to receive(:deliver_later) do + ActionMailer::Base.deliveries << mail + true + end + mail + end end it 'sends emails for each entry' do - expect(ResultsMailer).to receive(:entry_evaluation_notification).with(entry1, judging_round).and_call_original - expect(ResultsMailer).to receive(:entry_evaluation_notification).with(entry2, judging_round).and_call_original + # Verify the mailer was called with the correct arguments + expect(ResultsMailer).to receive(:entry_evaluation_notification).with(entry1, judging_round) + expect(ResultsMailer).to receive(:entry_evaluation_notification).with(entry2, judging_round) expect { post :send_round_results, params: {