From 9bb73b7cdd773608cded6daf83c109537e431835 Mon Sep 17 00:00:00 2001 From: Artur Beljajev <22315378+artur-beljajev@users.noreply.github.com> Date: Mon, 8 Jul 2019 13:45:45 +0300 Subject: [PATCH] Validate registrar's billing email (#1253) Previously it was being validated only if contact email changed (contact and billing emails have nothing in common). --- app/models/registrar.rb | 6 +++--- test/models/registrar_test.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 8a65c0b06..030c2a824 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -32,9 +32,9 @@ class Registrar < ActiveRecord::Base attribute :vat_rate, ::Type::VATRate.new after_initialize :set_defaults - validates :email, :billing_email, - email_format: { message: :invalid }, - allow_blank: true, if: proc { |c| c.email_changed? } + validates :email, email_format: { message: :invalid }, + allow_blank: true, if: proc { |c| c.email_changed? } + validates :billing_email, email_format: { message: :invalid }, allow_blank: true WHOIS_TRIGGERS = %w(name email phone street city state zip) diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index eec9007b6..15c276018 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -47,6 +47,22 @@ class RegistrarTest < ActiveSupport::TestCase assert registrar.invalid? end + def test_optional_billing_email + registrar = valid_registrar + registrar.billing_email = '' + assert registrar.valid? + end + + def test_billing_email_format_validation + registrar = valid_registrar + + registrar.billing_email = 'invalid' + assert registrar.invalid? + + registrar.billing_email = 'valid@email.test' + assert registrar.valid? + end + def test_invalid_without_language registrar = valid_registrar registrar.language = ''