Add extended registrar's info to "pending_deleted" mailer

#180
This commit is contained in:
Artur Beljajev 2016-11-03 20:16:01 +02:00
parent e52c747946
commit bebd49e5f4
11 changed files with 190 additions and 36 deletions

View file

@ -1,6 +1,45 @@
require 'rails_helper'
RSpec.describe DomainMailer do
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) }
@ -15,18 +54,15 @@ RSpec.describe DomainMailer do
end
it 'has sender' do
message.deliver!
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has recipient' do
expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com'])
message.deliver!
expect(message.to).to match_array(['recipient@test.com'])
end
it 'has valid subject' do
message.deliver!
expect(message.subject).to eq('Kustutusmenetluse teade')
end
@ -47,18 +83,15 @@ RSpec.describe DomainMailer do
end
it 'has sender' do
message.deliver!
expect(message.from).to eq(['noreply@internet.ee'])
end
it 'has recipient' do
expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com'])
message.deliver!
expect(message.to).to match_array(['recipient@test.com'])
end
it 'has valid subject' do
message.deliver!
expect(message.subject).to eq('The test.com domain has expired')
end

View file

@ -801,4 +801,22 @@ RSpec.describe Domain, db: false do
))
end
end
describe '#pending_delete!' do
let(:domain) { described_class.new }
let(:previous_registrant) { instance_double(Registrant) }
let(:message) { instance_double(Mail::Message) }
before :example do
expect(Registrant).to receive(:find).and_return(previous_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(message).to receive(:deliver)
domain.pending_delete!
end
end
end

View file

@ -0,0 +1,9 @@
require 'rails_helper'
RSpec.describe Registrant::DomainDeleteConfirmsController do
describe 'routing' do
it 'routes to #show' do
expect(get: '/registrant/domain_delete_confirms/1').to route_to('registrant/domain_delete_confirms#show', id: '1')
end
end
end

View file

@ -0,0 +1,41 @@
require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_deleted.html.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
assign(:verification_url, 'test url')
end
it 'has domain name' do
mention_count = 1 * lang_count
expect(domain).to receive(:name).exactly(mention_count).times.and_return('test domain name')
render
expect(rendered).to have_text('test domain name', count: mention_count)
end
it 'has verification url' do
mention_count = 1 * lang_count
render
expect(rendered).to have_text('test url', count: mention_count)
end
registrar_attributes = %i(
name
email
phone
url
)
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
end
end

View file

@ -0,0 +1,41 @@
require 'rails_helper'
RSpec.describe 'mailers/domain_mailer/pending_deleted.text.erb' do
let(:domain) { instance_spy(DomainPresenter) }
let(:registrar) { instance_spy(RegistrarPresenter) }
let(:lang_count) { 2 }
before :example do
assign(:domain, domain)
assign(:registrar, registrar)
end
it 'has domain name' do
mention_count = 1 * lang_count
expect(domain).to receive(:name).exactly(mention_count).times.and_return('test domain name')
render
expect(rendered).to have_text('test domain name', count: mention_count)
end
it 'has verification url' do
mention_count = 1 * lang_count
assign(:verification_url, 'test url')
render
expect(rendered).to have_text('test url', count: mention_count)
end
registrar_attributes = %i(
name
email
phone
url
)
registrar_attributes.each do |attr_name|
it "has registrar #{attr_name}" do
expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}")
render
expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count)
end
end
end