Refactor domain mailer views

#180
This commit is contained in:
Artur Beljajev 2016-11-12 01:14:11 +02:00
parent 962e98317d
commit a6de3761c5
57 changed files with 238 additions and 203 deletions

View file

@ -0,0 +1,18 @@
class DeleteDomainMailer < ApplicationMailer
include Que::Mailer
def pending(domain:, old_registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)
@verification_url = verification_url(domain)
subject = default_i18n_subject(domain_name: domain.name)
mail(to: old_registrant.email, subject: subject)
end
private
def verification_url(domain)
registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token)
end
end

View file

@ -1,21 +1,6 @@
class DomainMailer < ApplicationMailer
include Que::Mailer
def pending_update_request_for_old_registrant(domain:, registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)
@registrant = RegistrantPresenter.new(registrant: registrant, view: view_context)
@verification_url = registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token)
subject = default_i18n_subject(domain_name: domain.name)
mail(to: registrant.email, subject: subject)
end
def pending_update_notification_for_new_registrant(params)
compose_from(params)
end
def registrant_updated_notification_for_new_registrant(domain_id, old_registrant_id, new_registrant_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
return unless @domain
@ -45,23 +30,6 @@ class DomainMailer < ApplicationMailer
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_rejected_notification_for_new_registrant(params)
compose_from(params)
end
def pending_update_expired_notification_for_new_registrant(params)
compose_from(params)
end
def pending_deleted(domain:, registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)
@verification_url = registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token)
subject = default_i18n_subject(domain_name: domain.name)
mail(to: registrant.email, subject: subject)
end
def pending_delete_rejected_notification(domain_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
return unless @domain

View file

@ -0,0 +1,45 @@
class RegistrantChangeMailer < ApplicationMailer
include Que::Mailer
def confirmation(domain:, registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)
@registrant = RegistrantPresenter.new(registrant: registrant, view: view_context)
@verification_url = confirm_url(domain)
subject = default_i18n_subject(domain_name: domain.name)
mail(to: registrant.email, subject: subject)
end
def pending_update_notification_for_new_registrant(params)
compose_from(params)
end
def registrant_updated_notification_for_old_registrant(domain_id, old_registrant_id, new_registrant_id, should_deliver)
@domain = Domain.find_by(id: domain_id)
return unless @domain
return if delivery_off?(@domain, should_deliver)
@old_registrant = Registrant.find(old_registrant_id)
@new_registrant = Registrant.find(new_registrant_id)
return if whitelist_blocked?(@old_registrant.email)
mail(to: format(@old_registrant.email),
subject: "#{I18n.t(:registrant_updated_notification_for_old_registrant_subject,
name: @domain.name)} [#{@domain.name}]")
end
def pending_update_rejected_notification_for_new_registrant(params)
compose_from(params)
end
def pending_update_expired_notification_for_new_registrant(params)
compose_from(params)
end
private
def confirm_url(domain)
registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token)
end
end

View file

@ -379,6 +379,9 @@ class Domain < ActiveRecord::Base
new_registrant_email = registrant.email
new_registrant_name = registrant.name
current_registrant = Registrant.find(registrant_id_was)
RegistrantChangeMailer.confirmation(domain: self, current_registrant: current_registrant).deliver
send_mail :pending_update_request_for_old_registrant
send_mail :pending_update_notification_for_new_registrant
@ -441,8 +444,8 @@ class Domain < ActiveRecord::Base
pending_delete_confirmation!
save(validate: false) # should check if this did succeed
previous_registrant = Registrant.find(registrant_id_was)
DomainMailer.pending_deleted(domain: self, registrant: previous_registrant).deliver
old_registrant = Registrant.find(registrant_id_was)
DeleteDomainMailer.pending(domain: self, old_registrant: old_registrant).deliver
end
def cancel_pending_delete

View file

@ -37,13 +37,6 @@ class DomainMailModel
compose
end
def pending_deleted
registrant
subject(:domain_pending_deleted_subject)
confirm_delete
compose
end
def pending_delete_rejected_notification
registrant
subject(:pending_delete_rejected_notification_subject)
@ -107,10 +100,6 @@ class DomainMailModel
verification_url('domain_update_confirms')
end
def confirm_delete
verification_url('domain_delete_confirms')
end
def compose
@params
end

View file

@ -2,7 +2,7 @@ Tere
<br><br>
Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole:
<%= render 'mailers/domain_mailer/registrar/registrar.et.html', registrar: @registrar %>
<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %>
<br><br>
Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan.
@ -19,7 +19,7 @@ Hi,
<br><br>
Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. Incase of problems please contact your registrar:
<%= render 'mailers/domain_mailer/registrar/registrar.en.html', registrar: @registrar %>
<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %>
<br><br>
To confirm the update please visit this website, once again review the data and press approve:<br>

View file

@ -2,7 +2,7 @@ Tere
Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole:
<%= render 'mailers/domain_mailer/registrar/registrar.et.text', registrar: @registrar %>
<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %>
Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan.
@ -18,7 +18,7 @@ Hi,
Application for deletion of your domain <%= @domain.name %> has been filed. Please make sure that the application is correct. In case of problems please contact your registrar:
<%= render 'mailers/domain_mailer/registrar/registrar.en.text', registrar: @registrar %>
<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %>
To confirm the update please visit this website, once again review the data and press approve:
<%= @verification_url %>

View file

@ -0,0 +1,6 @@
en:
domain_mailer:
expiration:
subject: The %{domain_name} domain has expired
force_delete:
subject: Kustutusmenetluse teade

View file

@ -1,10 +1,4 @@
en:
domain_mailer:
pending_update_request_for_old_registrant:
subject: Kinnitustaotlus domeeni %{domain_name} registreerija vahetuseks / Application for approval for registrant change of %{domain_name}
expiration:
subject: The %{domain_name} domain has expired
force_delete:
subject: Kustutusmenetluse teade
pending_deleted:
delete_domain_mailer:
pending:
subject: Kinnitustaotlus domeeni %{domain_name} kustutamiseks .ee registrist / Application for approval for deletion of %{domain_name}

View file

@ -0,0 +1,4 @@
en:
registrant_change_mailer:
confirmation:
subject: Kinnitustaotlus domeeni %{domain_name} registreerija vahetuseks / Application for approval for registrant change of %{domain_name}

View file

@ -0,0 +1,42 @@
require 'rails_helper'
RSpec.describe DeleteDomainMailer do
describe '#pending' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:old_registrant) { instance_spy(Registrant, email: 'registrant@test.com') }
let(:domain_presenter) { instance_spy(DomainPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
subject(:message) { described_class.pending(domain: domain, old_registrant: old_registrant) }
before :example do
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
end
it 'has sender' do
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has old registrant email as a recipient' do
expect(message.to).to match_array(['registrant@test.com'])
end
it 'has subject' do
subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \
' / Application for approval for deletion of test.com'
expect(message.subject).to eq(subject)
end
it 'has confirmation url' do
allow(domain).to receive(:id).and_return(1)
expect(domain).to receive(:registrant_verification_token).and_return('test')
url = registrant_domain_delete_confirm_url(domain, token: 'test')
expect(message.body.parts.first.decoded).to include(url)
end
it 'sends message' do
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
end

View file

@ -1,88 +1,6 @@
require 'rails_helper'
RSpec.describe DomainMailer do
describe '#pending_update_request_for_old_registrant' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') }
let(:domain_presenter) { instance_spy(DomainPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
let(:registrant_presenter) { instance_spy(RegistrantPresenter) }
subject(:message) { described_class.pending_update_request_for_old_registrant(domain: domain,
registrant: registrant,
) }
before :example do
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter)
end
it 'has sender' do
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has registrant email as a recipient' do
expect(message.to).to match_array(['registrant@test.com'])
end
it 'has subject' do
subject = 'Kinnitustaotlus domeeni test.com registreerija vahetuseks' \
' / Application for approval for registrant change of test.com'
expect(message.subject).to eq(subject)
end
it 'has confirmation url' do
allow(domain).to receive(:id).and_return(1)
expect(domain).to receive(:registrant_verification_token).and_return('test')
url = registrant_domain_update_confirm_url(domain, token: 'test')
expect(message.body.parts.first.decoded).to include(url)
end
it 'sends message' do
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
describe '#pending_deleted' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') }
let(:domain_presenter) { instance_spy(DomainPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
subject(:message) { described_class.pending_deleted(domain: domain, registrant: registrant) }
before :example do
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
end
it 'has sender' do
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has registrant email as a recipient' do
expect(message.to).to match_array(['registrant@test.com'])
end
it 'has subject' do
subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \
' / Application for approval for deletion of test.com'
expect(message.subject).to eq(subject)
end
it 'has confirmation url' do
allow(domain).to receive(:id).and_return(1)
expect(domain).to receive(:registrant_verification_token).and_return('test')
url = registrant_domain_delete_confirm_url(domain, token: 'test')
expect(message.body.parts.first.decoded).to include(url)
end
it 'sends message' do
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
describe '#force_delete' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:domain_presenter) { instance_spy(DomainPresenter) }

View file

@ -0,0 +1,46 @@
require 'rails_helper'
RSpec.describe RegistrantChangeMailer do
describe '#confirmation' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') }
let(:domain_presenter) { instance_spy(DomainPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
let(:registrant_presenter) { instance_spy(RegistrantPresenter) }
subject(:message) { described_class.confirmation(domain: domain,
registrant: registrant,
) }
before :example do
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
expect(RegistrantPresenter).to receive(:new).and_return(registrant_presenter)
end
it 'has sender' do
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has registrant email as a recipient' do
expect(message.to).to match_array(['registrant@test.com'])
end
it 'has subject' do
subject = 'Kinnitustaotlus domeeni test.com registreerija vahetuseks' \
' / Application for approval for registrant change of test.com'
expect(message.subject).to eq(subject)
end
it 'has confirmation url' do
allow(domain).to receive(:id).and_return(1)
expect(domain).to receive(:registrant_verification_token).and_return('test')
url = registrant_domain_update_confirm_url(domain, token: 'test')
expect(message.body.parts.first.decoded).to include(url)
end
it 'sends message' do
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
end

View file

@ -822,17 +822,19 @@ RSpec.describe Domain, db: false do
describe '#pending_delete!' do
let(:domain) { described_class.new }
let(:previous_registrant) { instance_double(Registrant) }
let(:old_registrant) { instance_double(Registrant) }
let(:message) { instance_double(Mail::Message) }
before :example do
expect(Registrant).to receive(:find).and_return(previous_registrant)
expect(Registrant).to receive(:find).and_return(old_registrant)
allow(domain).to receive(:registrant_verification_asked?).and_return(true)
allow(domain).to receive(:save)
end
it 'sends notification email' do
expect(DomainMailer).to receive(:pending_deleted).with(domain: domain, registrant: previous_registrant).and_return(message)
expect(DeleteDomainMailer).to receive(:pending)
.with(domain: domain, old_registrant: old_registrant)
.and_return(message)
expect(message).to receive(:deliver)
domain.pending_delete!
end

View file

@ -0,0 +1,11 @@
require 'rails_helper'
require_relative 'pending_shared'
RSpec.describe 'mailers/delete_domain_mailer/pending.html.erb' do
before :example do
stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian'
stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english'
end
include_examples 'delete domain mailer pending'
end

View file

@ -0,0 +1,11 @@
require 'rails_helper'
require_relative 'pending_shared'
RSpec.describe 'mailers/delete_domain_mailer/pending.text.erb' do
before :example do
stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian'
stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english'
end
include_examples 'delete domain mailer pending'
end

View file

@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.shared_examples 'domain mailer pending deleted' do
RSpec.shared_examples 'delete domain mailer pending' do
let(:domain) { instance_spy(DomainPresenter) }
let(:lang_count) { 2 }

View file

@ -1,11 +0,0 @@
require 'rails_helper'
require_relative 'pending_deleted_shared'
RSpec.describe 'mailers/domain_mailer/pending_deleted.html.erb' do
before :example do
stub_template 'mailers/domain_mailer/registrar/_registrar.et.html' => 'test registrar estonian'
stub_template 'mailers/domain_mailer/registrar/_registrar.en.html' => 'test registrar english'
end
include_examples 'domain mailer pending deleted'
end

View file

@ -1,11 +0,0 @@
require 'rails_helper'
require_relative 'pending_deleted_shared'
RSpec.describe 'mailers/domain_mailer/pending_deleted.text.erb' do
before :example do
stub_template 'mailers/domain_mailer/registrar/_registrar.et.text' => 'test registrar estonian'
stub_template 'mailers/domain_mailer/registrar/_registrar.en.text' => 'test registrar english'
end
include_examples 'domain mailer pending deleted'
end

View file

@ -1,13 +0,0 @@
require 'rails_helper'
require_relative 'pending_update_request_for_old_registrant_shared'
RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb' do
before :example do
stub_template 'mailers/domain_mailer/registrar/_registrar.et.html' => 'test registrar estonian'
stub_template 'mailers/domain_mailer/registrar/_registrar.en.html' => 'test registrar english'
stub_template 'mailers/domain_mailer/registrant/_registrant.et.html' => 'test new registrant estonian'
stub_template 'mailers/domain_mailer/registrant/_registrant.en.html' => 'test new registrant english'
end
include_examples 'domain mailer pending update request for old registrant'
end

View file

@ -1,13 +0,0 @@
require 'rails_helper'
require_relative 'pending_update_request_for_old_registrant_shared'
RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb' do
before :example do
stub_template 'mailers/domain_mailer/registrar/_registrar.et.text' => 'test registrar estonian'
stub_template 'mailers/domain_mailer/registrar/_registrar.en.text' => 'test registrar english'
stub_template 'mailers/domain_mailer/registrant/_registrant.et.text' => 'test new registrant estonian'
stub_template 'mailers/domain_mailer/registrant/_registrant.en.text' => 'test new registrant english'
end
include_examples 'domain mailer pending update request for old registrant'
end

View file

@ -0,0 +1,13 @@
require 'rails_helper'
require_relative 'confirmation_shared'
RSpec.describe 'mailers/registrant_change_mailer/confirmation.html.erb' do
before :example do
stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian'
stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english'
stub_template 'mailers/shared/registrant/_registrant.et.html' => 'test new registrant estonian'
stub_template 'mailers/shared/registrant/_registrant.en.html' => 'test new registrant english'
end
include_examples 'domain mailer pending update request for old registrant'
end

View file

@ -0,0 +1,13 @@
require 'rails_helper'
require_relative 'confirmation_shared'
RSpec.describe 'mailers/registrant_change_mailer/confirmation.text.erb' do
before :example do
stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian'
stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english'
stub_template 'mailers/shared/registrant/_registrant.et.text' => 'test new registrant estonian'
stub_template 'mailers/shared/registrant/_registrant.en.text' => 'test new registrant english'
end
include_examples 'domain mailer pending update request for old registrant'
end