From 6356ce0e9f862fdc49b31ea7a9f478f4bbe18a7d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 4 Jul 2019 17:27:09 +0300 Subject: [PATCH] Fall back on contact email if billing email is absent Affects e-invoice and invoice delivery form. Fixes #1255 --- app/models/registrar.rb | 5 +++++ test/models/registrar_test.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/models/registrar.rb b/app/models/registrar.rb index de5b3a324a..fa8747114f 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -176,6 +176,11 @@ def e_invoice_iban iban end + def billing_email + return contact_email if self[:billing_email].blank? + self[:billing_email] + end + private def set_defaults diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index 7b3867f4a1..ae68ebeeae 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -63,6 +63,18 @@ def test_billing_email_format_validation assert registrar.valid? end + def test_returns_billing_email_when_provided + billing_email = 'billing@registrar.test' + registrar = Registrar.new(billing_email: billing_email) + assert_equal billing_email, registrar.billing_email + end + + def test_billing_email_fallback + contact_email = 'info@registrar.test' + registrar = Registrar.new(contact_email: contact_email, billing_email: '') + assert_equal contact_email, registrar.billing_email + end + def test_invalid_without_language registrar = valid_registrar registrar.language = ''