From c89c8a69bc5696cc2edc3eb994ac0b83ecd207ae Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 13 Jul 2023 18:24:57 +0100 Subject: [PATCH] optimize OrderMailer#invoice_email spec Check if the email was sent without raising an error Check if the email has an attached pdf --- spec/mailers/order_mailer_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index 86b7d96b50..5637978b16 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -228,6 +228,8 @@ describe Spree::OrderMailer do let(:generator){ double(:generator) } let(:renderer){ double(:renderer) } + let(:attachment_filename){ "invoice-#{order.number}.pdf" } + let(:deliveries){ ActionMailer::Base.deliveries } before do allow(OrderInvoiceGenerator).to receive(:new).with(order).and_return(generator) allow(InvoiceRenderer).to receive(:new).and_return(renderer) @@ -236,8 +238,13 @@ describe Spree::OrderMailer do it "should call the invoice render with order as argument" do expect(generator).not_to receive(:generate_or_update_latest_invoice) expect(order).not_to receive(:invoices) - expect(renderer).to receive(:render_to_string).with(order) - email.deliver_now + expect(renderer).to receive(:render_to_string).with(order).and_return("invoice") + expect { + email.deliver_now + }.to_not raise_error + expect(deliveries.count).to eq(1) + expect(deliveries.first.attachments.count).to eq(1) + expect(deliveries.first.attachments.first.filename).to eq(attachment_filename) end end