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