From 3e2a24ca62db6d2e5a12b80a03105493b624b369 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 1 Mar 2018 10:46:21 +0200 Subject: [PATCH] Do not validate Contact#country_code if address processing is off #731 --- app/models/contact.rb | 2 +- test/models/contact/postal_address_test.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/models/contact/postal_address_test.rb diff --git a/app/models/contact.rb b/app/models/contact.rb index 3024551f8..10b71b55b 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -37,7 +37,7 @@ class Contact < ActiveRecord::Base validates_associated :identifier validate :validate_html - validate :validate_country_code + validate :validate_country_code, if: 'self.class.address_processing?' after_initialize do self.status_notes = {} if status_notes.nil? diff --git a/test/models/contact/postal_address_test.rb b/test/models/contact/postal_address_test.rb new file mode 100644 index 000000000..645207a9f --- /dev/null +++ b/test/models/contact/postal_address_test.rb @@ -0,0 +1,19 @@ +require 'test_helper' + +class ContactPostalAddressTest < ActiveSupport::TestCase + def setup + @contact = contacts(:john) + end + + def test_invalid_if_country_code_is_invalid_and_address_processing_is_on + Setting.address_processing = true + @contact.country_code = 'invalid' + assert @contact.invalid? + end + + def test_valid_if_country_code_is_invalid_and_address_processing_is_off + Setting.address_processing = false + @contact.country_code = 'invalid' + assert @contact.valid? + end +end