Always require contact.registrar

This commit is contained in:
Artur Beljajev 2017-06-07 22:49:13 +03:00
parent af53313608
commit 821fabd083
2 changed files with 14 additions and 4 deletions

View file

@ -3,11 +3,11 @@ class Contact < ActiveRecord::Base
include EppErrors
include UserEvents
belongs_to :registrar
belongs_to :registrar, required: true
has_many :domain_contacts
has_many :domains, through: :domain_contacts
has_many :legal_documents, as: :documentable
has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id' # when contant is registrant
has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id'
# TODO: remove later
has_many :depricated_statuses, class_name: 'DepricatedContactStatus', dependent: :destroy
@ -19,7 +19,7 @@ class Contact < ActiveRecord::Base
accepts_nested_attributes_for :legal_documents
validates :name, :phone, :email, :ident, :ident_type, :registrar, presence: true
validates :name, :phone, :email, :ident, :ident_type, presence: true
validates :street, :city, :zip, :country_code, presence: true, if: 'self.class.address_processing?'
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/, phone: true

View file

@ -354,7 +354,7 @@ describe Contact, '.destroy_orphans' do
end
end
RSpec.describe Contact, db: false do
RSpec.describe Contact do
it { is_expected.to alias_attribute(:kind, :ident_type) }
describe '::names' do
@ -400,6 +400,16 @@ RSpec.describe Contact, db: false do
end
end
describe 'registrar validation', db: false do
let(:contact) { described_class.new }
it 'rejects absent' do
contact.registrar = nil
contact.validate
expect(contact.errors).to have_key(:registrar)
end
end
describe 'address validation', db: false do
let(:contact) { described_class.new }
subject(:errors) { contact.errors }