From 0916fe74c09453278efbf774e30c527df4923c0e Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Mon, 11 Feb 2019 16:10:57 -0600 Subject: [PATCH] Add a federated P2P creation email --- app/mailers/campaign_mailer.rb | 6 ++++ app/models/campaign.rb | 7 ++++- .../federated_creation_followup.html.erb | 31 +++++++++++++++++++ spec/models/campaign_spec.rb | 26 ++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 app/views/campaign_mailer/federated_creation_followup.html.erb create mode 100644 spec/models/campaign_spec.rb diff --git a/app/mailers/campaign_mailer.rb b/app/mailers/campaign_mailer.rb index c18aca9b..6919bef2 100644 --- a/app/mailers/campaign_mailer.rb +++ b/app/mailers/campaign_mailer.rb @@ -6,4 +6,10 @@ class CampaignMailer < BaseMailer @campaign = campaign mail(:to => @creator_profile.user.email, :subject => "Get your new campaign rolling! (via #{Settings.general.name})") end + + def federated_creation_followup(campaign) + @creator_profile = campaign.profile + @campaign = campaign + mail(:to => @creator_profile.user.email, :subject => "Get your new campaign rolling! (via #{Settings.general.name})") + end end diff --git a/app/models/campaign.rb b/app/models/campaign.rb index f0d62fcc..d4037873 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -101,7 +101,12 @@ class Campaign < ActiveRecord::Base after_create do user = self.profile.user Role.create(name: :campaign_editor, user_id: user.id, host: self) - CampaignMailer.delay.creation_followup(self) + if child_campaign? + CampaignMailer.delay.federated_creation_followup(self) + else + CampaignMailer.delay.creation_followup(self) + end + NonprofitAdminMailer.delay.supporter_fundraiser(self) unless QueryRoles.is_nonprofit_user?(user.id, self.nonprofit_id) self end diff --git a/app/views/campaign_mailer/federated_creation_followup.html.erb b/app/views/campaign_mailer/federated_creation_followup.html.erb new file mode 100644 index 00000000..8191ae0d --- /dev/null +++ b/app/views/campaign_mailer/federated_creation_followup.html.erb @@ -0,0 +1,31 @@ +<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%> +<% campaign_url = Format::Url.concat(root_url, @campaign.url) %> + +

Dear <%= @creator_profile.name.blank? ? @creator_profile.user.email : @creator_profile.name %>,

+
+ +

Congratulations on creating your campaign to support <%= @campaign.nonprofit.name %>!

+
+ +

You can visit it here: <%= campaign_url %>.

+
+ +

Before you share your campaign with the world, we recommend you personalize + your campaign by including a testimonial in your words about why + you launched your campaign. You can also set a goal amount to inspire you and your donors. + To edit your campaign, ">visit your fundraisers (you may be asked to login) + and select <%= @campaign.name%>.

+
+

Make sure to tell your friends and family why they should support your cause and how their contributions will make a difference. Your words and your passion can make a big difference. + Share your fundraiser on:

+ + +

If you need some help getting your campaign up and running, don't hesitate to contact <%= Settings.devise.mailer_sender %>.

+ +<%= render 'emails/sig' %> diff --git a/spec/models/campaign_spec.rb b/spec/models/campaign_spec.rb new file mode 100644 index 00000000..db5b4adb --- /dev/null +++ b/spec/models/campaign_spec.rb @@ -0,0 +1,26 @@ +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +require 'rails_helper' + +RSpec.describe Campaign, type: :model do + describe 'sends correct email based on type of campaign' do + let(:nonprofit) { force_create(:nonprofit)} + let(:parent_campaign) { force_create(:campaign, name: 'Parent campaign', nonprofit: nonprofit) } + let(:child_campaign) do + force_create(:campaign, + name: 'Child campaign', + parent_campaign_id: parent_campaign.id, + slug: "twehotiheiotheiofnieoth", + goal_amount_dollars: "1000", nonprofit: nonprofit ) + end + + it 'parent campaign sends out general campaign email' do + expect { parent_campaign }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect(ActionMailer::Base.deliveries.last.body.include?("Create one-time or recurring")).to be_truthy + end + + it 'child campaign sends out federated campaign email' do + expect { child_campaign}.to change { ActionMailer::Base.deliveries.count }.by(2) + expect(ActionMailer::Base.deliveries.last.body.include?("including a testimonial")).to be_truthy + end + end +end