Improve RegistrantChangeMailer

- Do not show registrant address unless "address_processing" is enabled
- Add missing registrant state and zip attributes

#480
This commit is contained in:
Artur Beljajev 2017-05-18 15:59:06 +03:00
parent 2c648ddc84
commit bfc0c0b74f
14 changed files with 164 additions and 43 deletions

View file

@ -1,4 +1,6 @@
class RegistrantChangeMailer < ApplicationMailer class RegistrantChangeMailer < ApplicationMailer
helper_method :address_processing
def confirm(domain:, registrar:, current_registrant:, new_registrant:) def confirm(domain:, registrar:, current_registrant:, new_registrant:)
@domain = DomainPresenter.new(domain: domain, view: view_context) @domain = DomainPresenter.new(domain: domain, view: view_context)
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
@ -42,4 +44,8 @@ class RegistrantChangeMailer < ApplicationMailer
def confirm_url(domain) def confirm_url(domain)
registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token) registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token)
end end
def address_processing
Contact.address_processing?
end
end end

View file

@ -594,4 +594,8 @@ class Contact < ActiveRecord::Base
return unless priv? return unless priv?
ident ident
end end
def ident_country
Country.new(ident_country_code)
end
end end

View file

@ -1,13 +1,20 @@
class RegistrantPresenter class RegistrantPresenter
delegate :name, :ident, :email, :priv?, :street, :city, :id_code, :reg_no, to: :registrant delegate :name, :ident, :email, :priv?, :id_code, :reg_no,
:street, :city, :state, :zip, :country,
:ident_country,
to: :registrant
def initialize(registrant:, view:) def initialize(registrant:, view:)
@registrant = registrant @registrant = registrant
@view = view @view = view
end end
def country def country(locale: I18n.locale)
registrant.country.translation(locale)
end
def ident_country(locale: I18n.locale)
registrant.ident_country.translation(locale)
end end
private private

View file

@ -4,6 +4,12 @@ Name: <%= registrant.name %><br>
<% else %> <% else %>
Business Registry code: <%= registrant.ident %><br> Business Registry code: <%= registrant.ident %><br>
<% end %> <% end %>
Street: <%= registrant.street %><br> <% if address_processing %>
City: <%= registrant.city %><br> Street: <%= registrant.street %><br>
Country: <%= registrant.country %> City: <%= registrant.city %><br>
State: <%= registrant.state %><br>
Zip-code: <%= registrant.zip %><br>
Country: <%= registrant.country %>
<% else %>
Country: <%= registrant.ident_country %>
<% end %>

View file

@ -4,6 +4,12 @@ Name: <%= registrant.name %>
<% else %> <% else %>
Business Registry code: <%= registrant.ident %> Business Registry code: <%= registrant.ident %>
<% end %> <% end %>
Street: <%= registrant.street %> <% if address_processing %>
City: <%= registrant.city %> Street: <%= registrant.street %>
Country: <%= registrant.country %> City: <%= registrant.city %>
State: <%= registrant.state %>
Zip-code: <%= registrant.zip %>
Country: <%= registrant.country %>
<% else %>
Country: <%= registrant.ident_country %>
<% end %>

View file

@ -4,6 +4,12 @@ Nimi: <%= registrant.name %><br>
<% else %> <% else %>
Äriregistrikood: <%= registrant.ident %><br> Äriregistrikood: <%= registrant.ident %><br>
<% end %> <% end %>
Tänav: <%= registrant.street %><br> <% if address_processing %>
Linn: <%= registrant.city %><br> Tänav: <%= registrant.street %><br>
Riik: <%= registrant.country %> Linn: <%= registrant.city %><br>
Maakond: <%= registrant.state %><br>
Sihtnumber: <%= registrant.zip %><br>
Riik: <%= registrant.country(locale: :et) %>
<% else %>
Riik: <%= registrant.ident_country(locale: :et) %>
<% end %>

View file

@ -4,6 +4,12 @@ Nimi: <%= registrant.name %>
<% else %> <% else %>
Äriregistrikood: <%= registrant.ident %> Äriregistrikood: <%= registrant.ident %>
<% end %> <% end %>
Tänav: <%= registrant.street %> <% if address_processing %>
Linn: <%= registrant.city %> Tänav: <%= registrant.street %>
Riik: <%= registrant.country %> Linn: <%= registrant.city %>
Maakond: <%= registrant.state %>
Sihtnumber: <%= registrant.zip %>
Riik: <%= registrant.country(locale: :et) %>
<% else %>
Riik: <%= registrant.ident_country(locale: :et) %>
<% end %>

View file

@ -523,4 +523,12 @@ RSpec.describe Contact, db: false do
specify { expect(contact.id_code).to be_nil } specify { expect(contact.id_code).to be_nil }
end end
end end
describe '#ident_country' do
let(:contact) { described_class.new(ident_country_code: 'US') }
it 'returns ident country' do
expect(contact.ident_country).to eq(Country.new('US'))
end
end
end end

View file

@ -4,29 +4,61 @@ RSpec.describe RegistrantPresenter do
let(:registrant) { instance_double(Registrant) } let(:registrant) { instance_double(Registrant) }
let(:presenter) { described_class.new(registrant: registrant, view: view) } let(:presenter) { described_class.new(registrant: registrant, view: view) }
registrant_delegate_attributes = %i( describe '#country' do
let(:country) { instance_double(Country) }
before :example do
allow(registrant).to receive(:country).and_return(country)
end
it 'returns country name in current locale by default' do
expect(country).to receive(:translation).with(I18n.locale).and_return('test country')
expect(presenter.country).to eq('test country')
end
it 'returns country name in given locale' do
expect(country).to receive(:translation).with(:de).and_return('test country')
expect(presenter.country(locale: :de)).to eq('test country')
end
end
describe '#ident_country' do
let(:ident_country) { instance_double(Country) }
before :example do
allow(registrant).to receive(:ident_country).and_return(ident_country)
end
it 'returns country name in current locale by default' do
expect(ident_country).to receive(:translation).with(I18n.locale).and_return('test country')
expect(presenter.ident_country).to eq('test country')
end
it 'returns country name in given locale' do
expect(ident_country).to receive(:translation).with(:de).and_return('test country')
expect(presenter.ident_country(locale: :de)).to eq('test country')
end
end
registrant_delegatable_attributes = %i(
name name
ident ident
email email
priv? priv?
street street
city city
state
zip
id_code id_code
reg_no reg_no
) )
registrant_delegate_attributes.each do |attribute_name| registrant_delegatable_attributes.each do |attr_name|
describe "##{attribute_name}" do describe "##{attr_name}" do
it 'delegetes to registrant' do it 'delegates to registrant' do
expect(registrant).to receive(attribute_name).and_return('test') expect(registrant).to receive(attr_name).and_return('test')
expect(presenter.send(attribute_name)).to eq('test') expect(presenter.send(attr_name)).to eq('test')
end end
end end
end end
describe '#country' do
it 'returns country name' do
expect(presenter.country).to be_nil
end
end
end end

View file

@ -2,5 +2,5 @@ require 'rails_helper'
require_relative 'registrant_shared' require_relative 'registrant_shared'
RSpec.describe 'mailers/shared/registrant/_registrant.en.html.erb' do RSpec.describe 'mailers/shared/registrant/_registrant.en.html.erb' do
include_examples 'domain mailer registrant info' include_examples 'domain mailer registrant info', 'mailers/shared/registrant/_registrant.en.html.erb'
end end

View file

@ -2,5 +2,5 @@ require 'rails_helper'
require_relative 'registrant_shared' require_relative 'registrant_shared'
RSpec.describe 'mailers/shared/registrant/_registrant.en.text.erb' do RSpec.describe 'mailers/shared/registrant/_registrant.en.text.erb' do
include_examples 'domain mailer registrant info' include_examples 'domain mailer registrant info', 'mailers/shared/registrant/_registrant.en.text.erb'
end end

View file

@ -2,5 +2,5 @@ require 'rails_helper'
require_relative 'registrant_shared' require_relative 'registrant_shared'
RSpec.describe 'mailers/shared/registrant/_registrant.et.html.erb' do RSpec.describe 'mailers/shared/registrant/_registrant.et.html.erb' do
include_examples 'domain mailer registrant info' include_examples 'domain mailer registrant info', 'mailers/shared/registrant/_registrant.et.html.erb'
end end

View file

@ -2,5 +2,5 @@ require 'rails_helper'
require_relative 'registrant_shared' require_relative 'registrant_shared'
RSpec.describe 'mailers/shared/registrant/_registrant.et.text.erb' do RSpec.describe 'mailers/shared/registrant/_registrant.et.text.erb' do
include_examples 'domain mailer registrant info' include_examples 'domain mailer registrant info', 'mailers/shared/registrant/_registrant.et.text.erb'
end end

View file

@ -1,25 +1,65 @@
require 'rails_helper' require 'rails_helper'
RSpec.shared_examples 'domain mailer registrant info' do RSpec.shared_examples 'domain mailer registrant info' do |template_path|
let(:template_path) { template_path }
let(:registrant) { instance_spy(RegistrantPresenter) } let(:registrant) { instance_spy(RegistrantPresenter) }
before :example do before :example do
allow(view).to receive(:registrant).and_return(registrant) allow(view).to receive(:registrant).and_return(registrant)
allow(view).to receive(:address_processing)
end end
attributes = %i( it 'has name' do
name allow(registrant).to receive(:name).and_return('test name')
ident render template: template_path
street expect(rendered).to have_text('test name')
city end
country
)
attributes.each do |attr_name| it 'has ident' do
it "has #{attr_name}" do allow(registrant).to receive(:ident).and_return('test ident')
expect(registrant).to receive(attr_name).and_return("test #{attr_name}") render template: template_path
render expect(rendered).to have_text('test ident')
expect(rendered).to have_text("test #{attr_name}") end
address_attributes = %i[street city state zip country]
context 'when address processing is enabled' do
before :example do
allow(view).to receive(:address_processing).and_return(true)
end
address_attributes.each do |attr_name|
it "has #{attr_name}" do
allow(registrant).to receive(attr_name).and_return("test #{attr_name}")
render template: template_path
expect(rendered).to have_text("test #{attr_name}")
end
end
it 'has no ident country' do
allow(registrant).to receive(:ident_country).and_return('test ident country')
render template: template_path
expect(rendered).to_not have_text('test ident country')
end
end
context 'when address processing is disabled' do
before :example do
allow(view).to receive(:address_processing).and_return(false)
end
address_attributes.each do |attr_name|
it "has no #{attr_name}" do
allow(registrant).to receive(attr_name).and_return("test #{attr_name}")
render template: template_path
expect(rendered).to_not have_text("test #{attr_name}")
end
end
it 'has ident country' do
allow(registrant).to receive(:ident_country).and_return('test ident country')
render template: template_path
expect(rendered).to have_text('test ident country')
end end
end end
end end