diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb
index dc493969c..07d55e11e 100644
--- a/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb
+++ b/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.html.erb
@@ -12,7 +12,7 @@ Nimi: <%= @new_registrant.name %>
Epost: <%= @new_registrant.email %>
Tänav: <%= @new_registrant.street %>
Linn: <%= @new_registrant.city %>
-Riik: <%= @new_registrant.country.name %>
+Riik: <%= @new_registrant.country.try(:name) %>
Lugupidamisega
Eesti Interneti Sihtasutus
@@ -33,7 +33,7 @@ Name: <%= @new_registrant.name %>
E-mail: <%= @new_registrant.email %>
Street: <%= @new_registrant.street %>
City: <%= @new_registrant.city %>
-Country: <%= @new_registrant.country.name %>
+Country: <%= @new_registrant.country.try(:name) %>
Best Regards,
Estonian Internet Foundation
diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb
index 0fd6a609e..bd53aa535 100644
--- a/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb
+++ b/app/views/mailers/domain_mailer/registrant_updated_notification_for_new_registrant.text.erb
@@ -13,7 +13,7 @@ Nimi: <%= @new_registrant.name %>
Epost: <%= @new_registrant.email %>
Tänav: <%= @new_registrant.street %>
Linn: <%= @new_registrant.city %>
-Riik: <%= @new_registrant.country.name %>
+Riik: <%= @new_registrant.country.try(:name) %>
Lugupidamisega
Eesti Interneti Sihtasutus
@@ -35,7 +35,7 @@ Name: <%= @new_registrant.name %>
E-mail: <%= @new_registrant.email %>
Street: <%= @new_registrant.street %>
City: <%= @new_registrant.city %>
-Country: <%= @new_registrant.country.name %>
+Country: <%= @new_registrant.country.try(:name) %>
Best Regards,
Estonian Internet Foundation
diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb
index 428994e36..3f0930d57 100644
--- a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb
+++ b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.html.erb
@@ -12,7 +12,7 @@ Isikukood: <%= @new_registrant.ident %>
Epost: <%= @new_registrant.email %>
Tänav: <%= @new_registrant.street %>
Linn: <%= @new_registrant.city %>
-Riik: <%= @new_registrant.country.name %>
+Riik: <%= @new_registrant.country.try(:name) %>
Lugupidamisega
Eesti Interneti Sihtasutus
@@ -33,7 +33,7 @@ Business Registry code: <%= @new_registrant.ident %>
E-mail: <%= @new_registrant.email %>
Street: <%= @new_registrant.street %>
City: <%= @new_registrant.city %>
-Country: <%= @new_registrant.country.name %>
+Country: <%= @new_registrant.country.try(:name) %>
Best Regards,
Estonian Internet Foundation
diff --git a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb
index a99eca6ba..5bf78a409 100644
--- a/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb
+++ b/app/views/mailers/domain_mailer/registrant_updated_notification_for_old_registrant.text.erb
@@ -13,7 +13,7 @@ Isikukood: <%= @new_registrant.ident %>
Epost: <%= @new_registrant.email %>
Tänav: <%= @new_registrant.street %>
Linn: <%= @new_registrant.city %>
-Riik: <%= @new_registrant.country.name %>
+Riik: <%= @new_registrant.country.try(:name) %>
Lugupidamisega
Eesti Interneti Sihtasutus
@@ -35,7 +35,7 @@ Business Registry code: <%= @new_registrant.ident %>
E-mail: <%= @new_registrant.email %>
Street: <%= @new_registrant.street %>
City: <%= @new_registrant.city %>
-Country: <%= @new_registrant.country.name %>
+Country: <%= @new_registrant.country.try(:name) %>
Best Regards,
Estonian Internet Foundation
diff --git a/spec/factories/contact.rb b/spec/factories/contact.rb
index 7122babd5..e47b67012 100644
--- a/spec/factories/contact.rb
+++ b/spec/factories/contact.rb
@@ -21,5 +21,19 @@ FactoryGirl.define do
ident_type 'org'
ident '12345678' # valid reg no for .ee
end
+
+ factory :contact_with_address do
+ street 'test'
+ city 'test'
+ zip 12345
+ country_code 'EE'
+ end
+
+ factory :contact_without_address do
+ street nil
+ city nil
+ zip nil
+ country_code nil
+ end
end
end
diff --git a/spec/factories/registrant.rb b/spec/factories/registrant.rb
index f25942829..d84d1688e 100644
--- a/spec/factories/registrant.rb
+++ b/spec/factories/registrant.rb
@@ -4,5 +4,7 @@ FactoryGirl.define do
factory :registrant_private_entity, class: Registrant, parent: :contact_private_entity
factory :registrant_legal_entity, class: Registrant, parent: :contact_legal_entity
+ factory :registrant_with_address, class: Registrant, parent: :contact_with_address
+ factory :registrant_without_address, class: Registrant, parent: :contact_without_address
end
end
diff --git a/spec/factory_lint_spec.rb b/spec/factory_lint_spec.rb
index 37988cca0..6269e3ec3 100644
--- a/spec/factory_lint_spec.rb
+++ b/spec/factory_lint_spec.rb
@@ -1,6 +1,10 @@
require_relative 'rails_helper'
RSpec.describe 'FactoryGirl', db: true do
+ before :example do
+ allow(Contact).to receive(:address_processing?).and_return(false)
+ end
+
it 'lints factories' do
FactoryGirl.lint
end
diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb
index a3f4a42c7..e05c5ad38 100644
--- a/spec/mailers/domain_mailer_spec.rb
+++ b/spec/mailers/domain_mailer_spec.rb
@@ -1,5 +1,59 @@
require 'rails_helper'
RSpec.describe DomainMailer do
+ describe '#registrant_updated_notification_for_new_registrant', db: true do
+ subject(:message) { described_class.registrant_updated_notification_for_new_registrant(55, 55, 55, true) }
+ context 'when contact address processing is enabled' do
+ before :example do
+ allow(Contact).to receive(:address_processing?).and_return(true)
+ create(:domain, id: 55)
+ create(:registrant_with_address, id: 55)
+ end
+
+ it 'sends message' do
+ expect { message.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
+ end
+ end
+
+ context 'when contact address processing is disabled' do
+ before :example do
+ allow(Contact).to receive(:address_processing?).and_return(false)
+ create(:domain, id: 55)
+ create(:registrant_without_address, id: 55)
+ end
+
+ it 'sends message' do
+ expect { message.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
+ end
+ end
+ end
+
+ describe '#registrant_updated_notification_for_old_registrant', db: true do
+ subject(:message) { described_class.registrant_updated_notification_for_old_registrant(55, 55, 55, true) }
+
+ context 'when contact address processing is enabled' do
+ before :example do
+ allow(Contact).to receive(:address_processing?).and_return(true)
+ create(:domain, id: 55)
+ create(:registrant_with_address, id: 55)
+ end
+
+ it 'sends message' do
+ expect { message.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
+ end
+ end
+
+ context 'when contact address processing is disabled' do
+ before :example do
+ allow(Contact).to receive(:address_processing?).and_return(false)
+ create(:domain, id: 55)
+ create(:registrant_without_address, id: 55)
+ end
+
+ it 'sends message' do
+ expect { message.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
+ end
+ end
+ end
end