diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb index 4523834e0..2a8620ee6 100644 --- a/app/mailers/registrant_change_mailer.rb +++ b/app/mailers/registrant_change_mailer.rb @@ -1,4 +1,6 @@ class RegistrantChangeMailer < ApplicationMailer + helper_method :address_processing + def confirm(domain:, registrar:, current_registrant:, new_registrant:) @domain = DomainPresenter.new(domain: domain, view: view_context) @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) @@ -42,4 +44,8 @@ class RegistrantChangeMailer < ApplicationMailer def confirm_url(domain) registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token) end + + def address_processing + Contact.address_processing? + end end diff --git a/app/models/contact.rb b/app/models/contact.rb index 5115a9ec9..6a833afde 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -594,4 +594,8 @@ class Contact < ActiveRecord::Base return unless priv? ident end + + def ident_country + Country.new(ident_country_code) + end end diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb index d18fd7cb6..6ea64d7e4 100644 --- a/app/presenters/registrant_presenter.rb +++ b/app/presenters/registrant_presenter.rb @@ -1,13 +1,20 @@ 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:) @registrant = registrant @view = view 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 private diff --git a/app/views/mailers/shared/registrant/_registrant.en.html.erb b/app/views/mailers/shared/registrant/_registrant.en.html.erb index 300157c83..83d2a3b10 100644 --- a/app/views/mailers/shared/registrant/_registrant.en.html.erb +++ b/app/views/mailers/shared/registrant/_registrant.en.html.erb @@ -4,6 +4,12 @@ Name: <%= registrant.name %>
<% else %> Business Registry code: <%= registrant.ident %>
<% end %> -Street: <%= registrant.street %>
-City: <%= registrant.city %>
-Country: <%= registrant.country %> +<% if address_processing %> + Street: <%= registrant.street %>
+ City: <%= registrant.city %>
+ State: <%= registrant.state %>
+ Zip-code: <%= registrant.zip %>
+ Country: <%= registrant.country %> +<% else %> + Country: <%= registrant.ident_country %> +<% end %> diff --git a/app/views/mailers/shared/registrant/_registrant.en.text.erb b/app/views/mailers/shared/registrant/_registrant.en.text.erb index 649e2c452..72cc91446 100644 --- a/app/views/mailers/shared/registrant/_registrant.en.text.erb +++ b/app/views/mailers/shared/registrant/_registrant.en.text.erb @@ -4,6 +4,12 @@ Name: <%= registrant.name %> <% else %> Business Registry code: <%= registrant.ident %> <% end %> -Street: <%= registrant.street %> -City: <%= registrant.city %> -Country: <%= registrant.country %> +<% if address_processing %> + Street: <%= registrant.street %> + City: <%= registrant.city %> + State: <%= registrant.state %> + Zip-code: <%= registrant.zip %> + Country: <%= registrant.country %> +<% else %> + Country: <%= registrant.ident_country %> +<% end %> diff --git a/app/views/mailers/shared/registrant/_registrant.et.html.erb b/app/views/mailers/shared/registrant/_registrant.et.html.erb index 789b88490..8857afd74 100644 --- a/app/views/mailers/shared/registrant/_registrant.et.html.erb +++ b/app/views/mailers/shared/registrant/_registrant.et.html.erb @@ -4,6 +4,12 @@ Nimi: <%= registrant.name %>
<% else %> Äriregistrikood: <%= registrant.ident %>
<% end %> -Tänav: <%= registrant.street %>
-Linn: <%= registrant.city %>
-Riik: <%= registrant.country %> +<% if address_processing %> + Tänav: <%= registrant.street %>
+ Linn: <%= registrant.city %>
+ Maakond: <%= registrant.state %>
+ Sihtnumber: <%= registrant.zip %>
+ Riik: <%= registrant.country(locale: :et) %> +<% else %> + Riik: <%= registrant.ident_country(locale: :et) %> +<% end %> diff --git a/app/views/mailers/shared/registrant/_registrant.et.text.erb b/app/views/mailers/shared/registrant/_registrant.et.text.erb index 01ece5e67..9a4601f4a 100644 --- a/app/views/mailers/shared/registrant/_registrant.et.text.erb +++ b/app/views/mailers/shared/registrant/_registrant.et.text.erb @@ -4,6 +4,12 @@ Nimi: <%= registrant.name %> <% else %> Äriregistrikood: <%= registrant.ident %> <% end %> -Tänav: <%= registrant.street %> -Linn: <%= registrant.city %> -Riik: <%= registrant.country %> +<% if address_processing %> + Tänav: <%= registrant.street %> + Linn: <%= registrant.city %> + Maakond: <%= registrant.state %> + Sihtnumber: <%= registrant.zip %> + Riik: <%= registrant.country(locale: :et) %> +<% else %> + Riik: <%= registrant.ident_country(locale: :et) %> +<% end %> diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 8c93d3545..f45da619c 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -523,4 +523,12 @@ RSpec.describe Contact, db: false do specify { expect(contact.id_code).to be_nil } 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 diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb index 73b28986e..f787fc2d3 100644 --- a/spec/presenters/registrant_presenter_spec.rb +++ b/spec/presenters/registrant_presenter_spec.rb @@ -4,29 +4,61 @@ RSpec.describe RegistrantPresenter do let(:registrant) { instance_double(Registrant) } 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 ident email priv? street city + state + zip id_code reg_no ) - registrant_delegate_attributes.each do |attribute_name| - describe "##{attribute_name}" do - it 'delegetes to registrant' do - expect(registrant).to receive(attribute_name).and_return('test') - expect(presenter.send(attribute_name)).to eq('test') + registrant_delegatable_attributes.each do |attr_name| + describe "##{attr_name}" do + it 'delegates to registrant' do + expect(registrant).to receive(attr_name).and_return('test') + expect(presenter.send(attr_name)).to eq('test') end end end - - describe '#country' do - it 'returns country name' do - expect(presenter.country).to be_nil - end - end end diff --git a/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb index a5e0d353b..54f4fef0e 100644 --- a/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.en.html.erb_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require_relative 'registrant_shared' 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 diff --git a/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb index fcfb85657..a66967bb7 100644 --- a/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.en.text.erb_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require_relative 'registrant_shared' 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 diff --git a/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb index ec4d134a8..f06c43ac3 100644 --- a/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.et.html.erb_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require_relative 'registrant_shared' 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 diff --git a/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb b/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb index 41b4c52eb..909c6f6be 100644 --- a/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb +++ b/spec/views/mailers/shared/registrant/_registrant.et.text.erb_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' require_relative 'registrant_shared' 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 diff --git a/spec/views/mailers/shared/registrant/registrant_shared.rb b/spec/views/mailers/shared/registrant/registrant_shared.rb index 07fcc3b1e..fb42b2a2e 100644 --- a/spec/views/mailers/shared/registrant/registrant_shared.rb +++ b/spec/views/mailers/shared/registrant/registrant_shared.rb @@ -1,25 +1,65 @@ 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) } before :example do allow(view).to receive(:registrant).and_return(registrant) + allow(view).to receive(:address_processing) end - attributes = %i( - name - ident - street - city - country - ) + it 'has name' do + allow(registrant).to receive(:name).and_return('test name') + render template: template_path + expect(rendered).to have_text('test name') + end - attributes.each do |attr_name| - it "has #{attr_name}" do - expect(registrant).to receive(attr_name).and_return("test #{attr_name}") - render - expect(rendered).to have_text("test #{attr_name}") + it 'has ident' do + allow(registrant).to receive(:ident).and_return('test ident') + render template: template_path + expect(rendered).to have_text('test ident') + 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