1
0
Fork 0

Add action MembershipApplicationMailer#tracking

This commit is contained in:
Alex Kotov 2018-12-06 21:37:08 +05:00
parent c637eaf8fa
commit 307e52d442
No known key found for this signature in database
GPG key ID: 4E831250F47DE154
10 changed files with 77 additions and 1 deletions

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
default from: Devise.mailer_sender
end

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
class MembershipApplicationMailer < ApplicationMailer
before_action :set_membership_application
def tracking
mail(
to: @membership_application.email,
subject: translate('membership_application_mailer.tracking.subject'),
)
end
private
def set_membership_application
@membership_application = params[:membership_application]
end
end

View file

@ -20,4 +20,10 @@ class MembershipApplication < ApplicationRecord
self.organization_membership = nil if organization_membership.blank?
self.comment = nil if comment.blank?
end
after_create do
MembershipApplicationMailer.with(
membership_application: self,
).tracking.deliver_now
end
end

View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
class MembershipApplicationPreview < ActionMailer::Preview
# http://localhost:3000/rails/mailers/membership_application/tracking
def tracking
membership_application = MembershipApplication.find params[:id]
MembershipApplicationMailer.with(
membership_application: membership_application,
).tracking
end
end

View file

@ -0,0 +1,4 @@
<p><%= translate '.lead_text' %></p>
<%= link_to membership_application_url(@membership_application),
membership_application_url(@membership_application) %>

View file

@ -36,6 +36,9 @@ module Partynest
# Fully qualified domain name.
config.site_domain = 'libertarian-party.com'
# ActionMailer previews
config.action_mailer.preview_path = Rails.root.join('app', 'previews')
# Don't generate system test files.
config.generators.system_tests = nil

View file

@ -14,6 +14,12 @@ en:
to browser bookmarks. Also the link to this page was sent to email
address which you have provided. You will be contacted by provided
contacts soon.
membership_application_mailer:
tracking:
subject: Your application is being processed
lead_text: >
You can track the status of your application by the following link.
You will be contacted by provided contacts soon.
passports:
show:
confirm: Confirm

View file

@ -14,6 +14,13 @@ ru:
Сохраните её в закладки браузера. Также на указанный вами адрес
электронной почты была отправлена ссылка на данную страницу.
В ближайшее время с вами свяжутся по указанным вами контактам.
membership_application_mailer:
tracking:
subject: Ваше заявление в обработке
lead_text: >
По приведённой ниже ссылке вы можете отслеживать статус вашего
заявления. В ближайшее время с вами свяжутся по указанным вами
контактам.
passports:
show:
confirm: Подтвердить

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe MembershipApplicationMailer do
pending "add some examples to (or delete) #{__FILE__}"
end

View file

@ -31,6 +31,11 @@ RSpec.describe 'POST /membership_applications' do
change(Account, :count).from(0).to(1)
end
specify do
expect { make_request }.to \
change(ActionMailer::Base.deliveries, :count).from(0).to(1)
end
context 'after request' do
before { make_request }
@ -48,6 +53,13 @@ RSpec.describe 'POST /membership_applications' do
country_state: country_state,
)
end
specify do
expect(ActionMailer::Base.deliveries.last).to have_attributes(
to: [MembershipApplication.last.email],
subject: I18n.t('membership_application_mailer.tracking.subject'),
)
end
end
context 'when country state is not specified' do