Note that there are some explanatory texts on larger screens.

plurals
  1. PORspec - How to test if mailer is using proper template
    text
    copied!<p>There is a lot info about how to test mailers.</p> <p>But I haven't found any resources how to test mailer to check if they REALLY use correct template.</p> <p>example:</p> <pre><code>class NewsletterMailer &lt; ActionMailer::Base include SendGrid default from: -&gt; { SystemConfiguration.newsletter_from_email } def send_newsletter_to_groups(newsletter_campaign_id, group_ids) newsletter_campaign = NewsletterCampaign.find newsletter_campaign_id emails = Group.where(:id =&gt; group_ids).map(&amp;:emails).flatten build_and_send_email(newsletter_campaign, emails) end end </code></pre> <p>on <code>app/views/newsletter_mailer/send_newsletter_to_group.html.erb</code> I have <strong>typo</strong>.</p> <p>I wrote <code>send_newsletter_to_group.html.erb</code> instead of <code>send_newsletter_to_groups.html.erb</code></p> <p>My spec still pass:</p> <pre><code>require "spec_helper" describe NewsletterMailer do before { create(:system_configuration) } let(:newsletter) { create(:newsletter_campaign) } describe '.send_newsletter_to_groups' do before do create(:system_configuration) create_list(:group, 3) create_list(:user, 2, groups: [Group.first], newsletter_subscription: true) create_list(:user, 2, groups: [Group.last], newsletter_subscription: true) create_list(:user, 2, name: "pippo") end let(:group_ids) { Group.pluck(:id) } subject { NewsletterMailer.send_newsletter_to_groups(newsletter.id, group_ids) } its(:to) { should == User.where("name != 'pippo'").map(&amp;:email) } its(:from) { should be_present } its(:subject) { should be_present } end end </code></pre> <p>But email doesn't contain body.</p> <p>It just send blank email, cuz at the name of the partial (<code>send_newsletter_to_group.html.erb</code>) I got typo.</p> <p>How to test this? In Mailer.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload