From 60d564d0987042d7e97374eff60845a4bf1cc718 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 4 May 2015 14:41:27 +0300 Subject: [PATCH] Added missing CID for custom code --- app/models/epp/contact.rb | 7 ++++--- app/models/registrar.rb | 4 ++++ spec/epp/contact_spec.rb | 34 +++++++++++++++++----------------- spec/models/registrar_spec.rb | 4 ++++ 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 24ba0e671..ecb7219f2 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -55,10 +55,11 @@ class Epp::Contact < Contact # add prefix when needed if custom_code.present? - prefix, custom = custom_code.split(':') - if prefix != registrar.code && custom != registrar.code - custom_code = "#{registrar.code}:#{custom_code}" + cid, rcode, custom = custom_code.split(':') + if "#{cid}:#{rcode}" != registrar.contact_prefix + custom_code = "#{registrar.contact_prefix}:#{custom_code}" end + custom_code = nil if custom_code == registrar.contact_prefix end super( diff --git a/app/models/registrar.rb b/app/models/registrar.rb index d297545a3..d42c9a281 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -140,4 +140,8 @@ class Registrar < ActiveRecord::Base def code=(code) self[:code] = code.gsub(/[ :]/, '').upcase if new_record? && code.present? end + + def contact_prefix + "CID:#{code}" + end end diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 7b464eff1..ee2481d34 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -142,20 +142,20 @@ describe 'EPP Contact', epp: true do cr_date.text.to_time.should be_within(5).of(Time.zone.now) end - it 'should add registrar prefix for code when missing' do - response = create_request({ id: { value: 'abc:ABC:12345' } }) - response[:msg].should == 'Command completed successfully' - response[:result_code].should == '1000' - - Contact.last.code.should == 'FIRST0:abc:ABC:12345' - end - it 'should add registrar prefix for code when missing' do response = create_request({ id: { value: 'abc12345' } }) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' - Contact.last.code.should == 'FIRST0:abc12345' + Contact.last.code.should == 'CID:FIRST0:abc12345' + end + + it 'should add registrar prefix for code when missing' do + response = create_request({ id: { value: 'abc:ABC:12345' } }) + response[:msg].should == 'Command completed successfully' + response[:result_code].should == '1000' + + Contact.last.code.should == 'CID:FIRST0:abc:ABC:12345' end it 'should not allow spaces in custom code' do @@ -165,31 +165,31 @@ describe 'EPP Contact', epp: true do end it 'should not add registrar prefix for code when prefix present' do - response = create_request({ id: { value: 'FIRST0:abc:ABC:NEW:12345' } }) + response = create_request({ id: { value: 'CID:FIRST0:abc:ABC:NEW:12345' } }) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' - Contact.last.code.should == 'FIRST0:abc:ABC:NEW:12345' + Contact.last.code.should == 'CID:FIRST0:abc:ABC:NEW:12345' end it 'should not add registrar prefix for code when prefix present' do - response = create_request({ id: { value: 'FIRST0:abc22' } }) + response = create_request({ id: { value: 'CID:FIRST0:abc22' } }) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' - Contact.last.code.should == 'FIRST0:abc22' + Contact.last.code.should == 'CID:FIRST0:abc22' end it 'should add registrar prefix for code does not match exactly to prefix' do - response = create_request({ id: { value: 'first0:abc:ABC:11111' } }) + response = create_request({ id: { value: 'cid:first0:abc:ABC:11111' } }) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' - Contact.last.code.should == 'FIRST0:first0:abc:ABC:11111' + Contact.last.code.should == 'CID:FIRST0:cid:first0:abc:ABC:11111' end - it 'should ignore custom code when value is prefix' do - response = create_request({ id: { value: 'FIRST0' } }) + it 'should ignore custom code when only contact prefix given' do + response = create_request({ id: { value: 'CID:FIRST0' } }) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb index 208ae9906..63099712f 100644 --- a/spec/models/registrar_spec.rb +++ b/spec/models/registrar_spec.rb @@ -89,6 +89,10 @@ describe Registrar do registrar.code.should == 'WITH.DOT' end + it 'should have contact prefix' do + @registrar.contact_prefix.should == 'CID:REGISTRAR0' + end + it 'should have one version' do with_versioning do @registrar.versions.should == []