From fde5be293d80cf83f9a2f22829f0ad1120f763eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 12 Mar 2025 00:50:19 +0100 Subject: [PATCH] Move mailer tests to the right file These tests were testing mailer methods, but were inside a file for system tests. We're moving them now because these tests use the `open_last_email` method, and we're looking for places where using this method might result in a flaky test when used inside a system test. --- spec/mailers/mailer_spec.rb | 30 ++++++++++++++++++++++ spec/system/admin/machine_learning_spec.rb | 22 ---------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/spec/mailers/mailer_spec.rb b/spec/mailers/mailer_spec.rb index 4f93ef388..25d5887d8 100644 --- a/spec/mailers/mailer_spec.rb +++ b/spec/mailers/mailer_spec.rb @@ -116,4 +116,34 @@ describe Mailer do end end end + + describe "#machine_learning_success" do + let(:admin) { create(:administrator) } + + it "is delivered to the user who executes the script" do + Mailer.machine_learning_success(admin.user).deliver + + email = open_last_email + expect(email).to have_subject "Machine Learning - Content has been generated successfully" + expect(email).to have_content "Machine Learning script" + expect(email).to have_content "Content has been generated successfully." + expect(email).to have_link "Visit Machine Learning panel" + expect(email).to deliver_to(admin.user.email) + end + end + + describe "#machine_learning_error" do + let(:admin) { create(:administrator) } + + it "is delivered to the user who executes the script" do + Mailer.machine_learning_error(admin.user).deliver + + email = open_last_email + expect(email).to have_subject "Machine Learning - An error has occurred running the script" + expect(email).to have_content "Machine Learning script" + expect(email).to have_content "An error has occurred running the Machine Learning script." + expect(email).to have_link "Visit Machine Learning panel" + expect(email).to deliver_to(admin.user.email) + end + end end diff --git a/spec/system/admin/machine_learning_spec.rb b/spec/system/admin/machine_learning_spec.rb index 0332b4db9..37a7d0dcb 100644 --- a/spec/system/admin/machine_learning_spec.rb +++ b/spec/system/admin/machine_learning_spec.rb @@ -146,28 +146,6 @@ describe "Machine learning" do expect(page).to have_button "Execute script" end - scenario "Email content received by the user who execute the script" do - reset_mailer - Mailer.machine_learning_success(admin.user).deliver - - email = open_last_email - expect(email).to have_subject "Machine Learning - Content has been generated successfully" - expect(email).to have_content "Machine Learning script" - expect(email).to have_content "Content has been generated successfully." - expect(email).to have_link "Visit Machine Learning panel" - expect(email).to deliver_to(admin.user.email) - - reset_mailer - Mailer.machine_learning_error(admin.user).deliver - - email = open_last_email - expect(email).to have_subject "Machine Learning - An error has occurred running the script" - expect(email).to have_content "Machine Learning script" - expect(email).to have_content "An error has occurred running the Machine Learning script." - expect(email).to have_link "Visit Machine Learning panel" - expect(email).to deliver_to(admin.user.email) - end - scenario "Machine Learning visualization settings are disabled by default" do allow_any_instance_of(MachineLearning).to receive(:run) do MachineLearningJob.first.update!(finished_at: Time.current)