mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Make street, city, zip and country optional if address processing is disabled
#251
This commit is contained in:
parent
5e1c43f7cc
commit
cefd310cc0
2 changed files with 37 additions and 2 deletions
|
@ -18,8 +18,8 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
accepts_nested_attributes_for :legal_documents
|
||||
|
||||
validates :name, :phone, :email, :ident, :ident_type,
|
||||
:street, :city, :zip, :country_code, :registrar, presence: true
|
||||
validates :name, :phone, :email, :ident, :ident_type, :registrar, presence: true
|
||||
validates :street, :city, :zip, :country_code, presence: true, if: 'self.class.address_processing?'
|
||||
|
||||
# Phone nr validation is very minimam in order to support legacy requirements
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/
|
||||
|
|
|
@ -406,4 +406,39 @@ RSpec.describe Contact, db: false do
|
|||
expect(described_class.address_attribute_names).to eq(attributes)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'address validation', db: false do
|
||||
let(:contact) { described_class.new }
|
||||
subject(:errors) { contact.errors }
|
||||
|
||||
required_attributes = %i(street city zip country_code)
|
||||
|
||||
context 'when address processing is enabled' do
|
||||
before do
|
||||
allow(described_class).to receive(:address_processing?).and_return(true)
|
||||
end
|
||||
|
||||
required_attributes.each do |attr_name|
|
||||
it "rejects absent #{attr_name}" do
|
||||
contact.send("#{attr_name}=", nil)
|
||||
contact.validate
|
||||
expect(errors).to have_key(attr_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when address processing is disabled' do
|
||||
before do
|
||||
allow(described_class).to receive(:address_processing?).and_return(false)
|
||||
end
|
||||
|
||||
required_attributes.each do |attr_name|
|
||||
it "accepts absent #{attr_name}" do
|
||||
contact.send("#{attr_name}=", nil)
|
||||
contact.validate
|
||||
expect(errors).to_not have_key(attr_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue