create#contacts refactor

This commit is contained in:
Andres Keskküla 2014-08-06 11:38:21 +03:00
parent 2adbd915f7
commit 813674c965
4 changed files with 28 additions and 6 deletions

View file

@ -1,11 +1,13 @@
module Epp::ContactsHelper
def create_contact
@contact = Contact.new( contact_and_address_attributes )
stamp @contact
@contact.save
render '/epp/contacts/create'
if @contact.save
render '/epp/contacts/create'
else
handle_contact_errors
render '/epp/error'
end
end
def delete_contact
@ -45,7 +47,7 @@ module Epp::ContactsHelper
@contact = Contact.where(code: ph[:id]).first
case has_rights
when true
render '/epp/contacts/info'
render 'epp/contacts/info'
when false
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
render 'epp/error'
@ -98,4 +100,13 @@ module Epp::ContactsHelper
return nil
end
def handle_contact_errors # handle_errors conflicted with domain logic
handle_epp_errors({
'2302' => [:epp_id_taken],
'2303' => [:not_found, :epp_obj_does_not_exist]
}, @contact
)
end
end

View file

@ -15,6 +15,7 @@ class Contact < ActiveRecord::Base
validate :ident_must_be_valid
validates :phone, format: { with: /\+\d{3}\.\d+/, message: "bad format" }
validates_uniqueness_of :code, message: :epp_id_taken
IDENT_TYPE_ICO = 'ico'
IDENT_TYPES = [

View file

@ -66,3 +66,4 @@ en:
epp_command_failed: 'Command failed'
epp_nameservers_range_fail: 'Domain must have %{min}-%{max} nameservers'
epp_authorization_error: 'Authorization error'
epp_id_taken: 'Contact id already exists'

View file

@ -19,6 +19,16 @@ describe 'EPP Contact', epp: true do
expect(Contact.first.org_name).to eq('Example Inc.')
end
it 'does not create duplicate contact' do
Fabricate(:contact, code: 'sh8013')
response = epp_request('contacts/create.xml')
expect(response[:result_code]).to eq('2302')
expect(response[:msg]).to eq('Contact id already exists')
expect(Contact.count).to eq(1)
end
it 'updates a contact with same ident', pending: true do
pending 'fixing this as soon as contact#update is done'
Fabricate(:contact)
@ -56,7 +66,6 @@ describe 'EPP Contact', epp: true do
it 'checks contacts' do
Fabricate(:contact)
Fabricate(:contact, id:'sh8914')
response = epp_request('contacts/check.xml')
expect(response[:result_code]).to eq('1000')