Basic contact delete command implementation

This commit is contained in:
Andres Keskküla 2014-07-28 12:00:55 +03:00
parent 1645b3e96f
commit 65bb5166cc
7 changed files with 65 additions and 1 deletions

View file

@ -11,4 +11,8 @@ class Epp::CommandsController < ApplicationController
def check
send("check_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
end
def delete
send("delete_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
end
end

View file

@ -22,4 +22,22 @@ module Epp::ContactsHelper
@contact.save
render '/epp/contacts/create'
end
def delete_contact
ph = params_hash['epp']['command']['delete']['delete']
begin
@contact = Contact.where(code: ph[:id]).first
@contact.destroy
render '/epp/contacts/delete'
rescue NoMethodError => e
@code = '2303'
@msg = "Object does not exist"
render '/epp/error'
rescue
@code = '2400'
@msg = "Command failed"
render '/epp/error'
end
end
end

View file

@ -1,6 +1,7 @@
class Contact < ActiveRecord::Base
#TODO Foreign contact will get email with activation link/username/temp password
#TODO Phone number validation, in first phase very minimam in order to support current registries
has_many :addresses
validate :ident_must_be_valid

View file

@ -0,0 +1,9 @@
xml.epp_head do
xml.response do
xml.result('code' => '1000') do
xml.msg 'Command completed successfully'
end
xml << render('/epp/shared/trID')
end
end

View file

@ -17,15 +17,34 @@ describe 'EPP Contact', epp: true do
end
it 'updates a contact with same ident' do
Fabricate(:contact)
response = epp_request('contacts/create.xml')
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
expect(response[:clTRID]).to eq('ABC-12345')
expect(Contact.first.name).to eq("John Doe")
expect(Contact.count).to eq(1)
end
#TODO tests for missing/invalid/etc ident
it 'deletes contact' do
Fabricate(:contact)
response = epp_request('contacts/delete.xml')
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
expect(response[:clTRID]).to eq('ABC-12345')
expect(Contact.count).to eq(0)
end
it 'deletes an nil object' do
response = epp_request('contacts/delete.xml')
expect(response[:result_code]).to eq('2303')
expect(response[:msg]).to eq('Object does not exist')
end
end
end

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<delete>
<contact:delete
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>sh8913</contact:id>
</contact:delete>
</delete>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -3,4 +3,5 @@ Fabricator(:contact) do
phone '+372.12345678'
email Faker::Internet.email
ident '37605030299'
code 'sh8913'
end