Merge branch 'master' of github.com:internetee/registry

This commit is contained in:
Martin Lensment 2014-09-19 13:22:18 +03:00
commit ae40264a2d
3 changed files with 12 additions and 10 deletions

View file

@ -1,6 +1,7 @@
module Epp::ContactsHelper module Epp::ContactsHelper
def create_contact def create_contact
@contact = Contact.new(contact_and_address_attributes) @contact = Contact.new(contact_and_address_attributes)
@contact.generate_code
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
handle_errors(@contact) handle_errors(@contact)
@ -54,7 +55,7 @@ module Epp::ContactsHelper
## CREATE ## CREATE
def validate_contact_create_request def validate_contact_create_request
@ph = params_hash['epp']['command']['create']['create'] @ph = params_hash['epp']['command']['create']['create']
xml_attrs_present?(@ph, [%w(id), %w(authInfo pw), %w(postalInfo)]) xml_attrs_present?(@ph, [ %w(authInfo pw), %w(postalInfo)])
return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array) return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)

View file

@ -4,8 +4,8 @@ class Contact < ActiveRecord::Base
include EppErrors include EppErrors
has_one :local_address has_one :local_address, dependent: :destroy
has_one :international_address has_one :international_address, dependent: :destroy
has_one :disclosure, class_name: 'ContactDisclosure' has_one :disclosure, class_name: 'ContactDisclosure'
has_many :domain_contacts has_many :domain_contacts
@ -78,6 +78,12 @@ class Contact < ActiveRecord::Base
auth_info == pw auth_info == pw
end end
# generate random id for contact
#
def generate_code
self.code = SecureRandom.hex(4)
end
# Find a way to use self.domains with contact # Find a way to use self.domains with contact
def domains_owned def domains_owned
Domain.where(owner_contact_id: id) Domain.where(owner_contact_id: id)
@ -90,7 +96,6 @@ class Contact < ActiveRecord::Base
# should use only in transaction # should use only in transaction
def destroy_and_clean def destroy_and_clean
clean_up_address
if relations_with_domain? if relations_with_domain?
errors.add(:domains, :exist) errors.add(:domains, :exist)
@ -153,8 +158,4 @@ class Contact < ActiveRecord::Base
end end
private private
def clean_up_address
address.destroy if address
end
end end

View file

@ -69,13 +69,13 @@ describe 'EPP Contact', epp: true do
id = response[:parsed].css('resData creData id').first id = response[:parsed].css('resData creData id').first
cr_date = response[:parsed].css('resData creData crDate').first cr_date = response[:parsed].css('resData creData crDate').first
expect(id.text).to eq('sh8013') expect(id.text.length).to eq(8)
# 5 seconds for what-ever weird lag reasons might happen # 5 seconds for what-ever weird lag reasons might happen
expect(cr_date.text.to_time).to be_within(5).of(Time.now) expect(cr_date.text.to_time).to be_within(5).of(Time.now)
end end
it 'does not create duplicate contact' do it 'does not create duplicate contact', pending: true do
Fabricate(:contact, code: 'sh8013') Fabricate(:contact, code: 'sh8013')
response = epp_request(contact_create_xml, :xml) response = epp_request(contact_create_xml, :xml)