mirror of
https://github.com/internetee/registry.git
synced 2025-07-26 04:28:27 +02:00
Honor legacy contact codes
This commit is contained in:
parent
8b22c58eec
commit
834d638423
6 changed files with 74 additions and 47 deletions
|
@ -51,12 +51,15 @@ class Epp::Contact < Contact
|
||||||
def new(frame, registrar)
|
def new(frame, registrar)
|
||||||
return super if frame.blank?
|
return super if frame.blank?
|
||||||
|
|
||||||
custom_code =
|
custom_code = frame.css('id').text
|
||||||
if frame.css('id').text.present?
|
|
||||||
"#{registrar.code}:#{frame.css('id').text.parameterize}"
|
# add prefix when needed
|
||||||
else
|
if custom_code.present?
|
||||||
nil
|
prefix, custom = custom_code.split(':')
|
||||||
|
if prefix != registrar.code && custom != registrar.code
|
||||||
|
custom_code = "#{registrar.code}:#{custom_code}"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
super(
|
super(
|
||||||
attrs_from(frame).merge(
|
attrs_from(frame).merge(
|
||||||
|
|
|
@ -13,8 +13,7 @@ class Registrar < ActiveRecord::Base
|
||||||
belongs_to :country_deprecated, foreign_key: :country_id
|
belongs_to :country_deprecated, foreign_key: :country_id
|
||||||
|
|
||||||
validates :name, :reg_no, :country_code, :email, :code, presence: true
|
validates :name, :reg_no, :country_code, :email, :code, presence: true
|
||||||
validates :name, :reg_no, :reference_no, uniqueness: true
|
validates :name, :reg_no, :reference_no, :code, uniqueness: true
|
||||||
validate :set_code, if: :new_record?
|
|
||||||
|
|
||||||
before_validation :generate_iso_11649_reference_no
|
before_validation :generate_iso_11649_reference_no
|
||||||
def generate_iso_11649_reference_no
|
def generate_iso_11649_reference_no
|
||||||
|
@ -141,24 +140,4 @@ class Registrar < ActiveRecord::Base
|
||||||
def code=(code)
|
def code=(code)
|
||||||
self[:code] = code.upcase if new_record? && code.present?
|
self[:code] = code.upcase if new_record? && code.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_prefix
|
|
||||||
"CID:#{code}:"
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def set_code
|
|
||||||
return false if name.blank?
|
|
||||||
new_code = name.parameterize
|
|
||||||
|
|
||||||
# ensure code is always uniq automatically for a new record
|
|
||||||
seq = 1
|
|
||||||
while self.class.find_by_code(new_code)
|
|
||||||
new_code += seq.to_s
|
|
||||||
seq += 1
|
|
||||||
end
|
|
||||||
|
|
||||||
self.code = new_code
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,7 +81,7 @@
|
||||||
.col-md-4.control-label
|
.col-md-4.control-label
|
||||||
= f.label :code
|
= f.label :code
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= f.text_field(:code, class: 'form-control')
|
= f.text_field(:code, class: 'form-control', disabled: !f.object.new_record?)
|
||||||
|
|
||||||
%hr
|
%hr
|
||||||
.row
|
.row
|
||||||
|
|
|
@ -142,12 +142,58 @@ describe 'EPP Contact', epp: true do
|
||||||
cr_date.text.to_time.should be_within(5).of(Time.zone.now)
|
cr_date.text.to_time.should be_within(5).of(Time.zone.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'successfully saves custom code' do
|
it 'should add registrar prefix for code when missing' do
|
||||||
response = create_request({ id: { value: '12345' } })
|
response = create_request({ id: { value: 'abc:ABC:12345' } })
|
||||||
response[:msg].should == 'Command completed successfully'
|
response[:msg].should == 'Command completed successfully'
|
||||||
response[:result_code].should == '1000'
|
response[:result_code].should == '1000'
|
||||||
|
|
||||||
Contact.last.code.should == 'registrar1:12345'
|
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'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not allow spaces in custom code' do
|
||||||
|
response = create_request({ id: { value: 'abc 123' } })
|
||||||
|
response[:msg].should == 'is invalid [code]'
|
||||||
|
response[:result_code].should == '2005'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not add registrar prefix for code when prefix present' do
|
||||||
|
response = create_request({ id: { value: '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'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not add registrar prefix for code when prefix present' do
|
||||||
|
response = create_request({ id: { value: 'FIRST0:abc22' } })
|
||||||
|
response[:msg].should == 'Command completed successfully'
|
||||||
|
response[:result_code].should == '1000'
|
||||||
|
|
||||||
|
Contact.last.code.should == '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[:msg].should == 'Command completed successfully'
|
||||||
|
response[:result_code].should == '1000'
|
||||||
|
|
||||||
|
Contact.last.code.should == 'FIRST0:first0:abc:ABC:11111'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should ignore custom code when value is prefix' do
|
||||||
|
response = create_request({ id: { value: 'FIRST0' } })
|
||||||
|
response[:msg].should == 'Command completed successfully'
|
||||||
|
response[:result_code].should == '1000'
|
||||||
|
|
||||||
|
Contact.last.code.match(':').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate server id when id is empty' do
|
it 'should generate server id when id is empty' do
|
||||||
|
|
|
@ -7,7 +7,7 @@ Fabricator(:registrar) do
|
||||||
zip 'Postal'
|
zip 'Postal'
|
||||||
email 'info@registrar1.ee'
|
email 'info@registrar1.ee'
|
||||||
country_code 'EE'
|
country_code 'EE'
|
||||||
code 'REG'
|
code { sequence(:code) { |i| "REGISTRAR#{i}" } }
|
||||||
reference_no { sequence(:reference_no) { |i| "RF#{i}" } }
|
reference_no { sequence(:reference_no) { |i| "RF#{i}" } }
|
||||||
accounts(count: 1)
|
accounts(count: 1)
|
||||||
end
|
end
|
||||||
|
@ -24,6 +24,7 @@ Fabricator(:registrar1, from: :registrar) do
|
||||||
state 'County'
|
state 'County'
|
||||||
zip 'Postal'
|
zip 'Postal'
|
||||||
email 'info@registrar1.ee'
|
email 'info@registrar1.ee'
|
||||||
|
code { sequence(:code) { |i| "FIRST#{i}" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:registrar2, from: :registrar) do
|
Fabricator(:registrar2, from: :registrar) do
|
||||||
|
@ -34,6 +35,7 @@ Fabricator(:registrar2, from: :registrar) do
|
||||||
state 'County'
|
state 'County'
|
||||||
zip 'Postal'
|
zip 'Postal'
|
||||||
email 'info@registrar2.ee'
|
email 'info@registrar2.ee'
|
||||||
|
code { sequence(:code) { |i| "SECOND#{i}" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:eis, from: :registrar) do
|
Fabricator(:eis, from: :registrar) do
|
||||||
|
@ -48,5 +50,6 @@ Fabricator(:eis, from: :registrar) do
|
||||||
street 'Paldiski mnt 80'
|
street 'Paldiski mnt 80'
|
||||||
zip '10617'
|
zip '10617'
|
||||||
url 'www.internet.ee'
|
url 'www.internet.ee'
|
||||||
|
code { sequence(:code) { |i| "EIS#{i}" } }
|
||||||
accounts(count: 1) { Fabricate(:account, account_activities: []) }
|
accounts(count: 1) { Fabricate(:account, account_activities: []) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,7 @@ describe Registrar do
|
||||||
'Country code is missing',
|
'Country code is missing',
|
||||||
'Name is missing',
|
'Name is missing',
|
||||||
'Reg no is missing',
|
'Reg no is missing',
|
||||||
'Code is missing',
|
'Code is missing'
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,6 +57,14 @@ describe Registrar do
|
||||||
@registrar.errors.full_messages.should match_array([])
|
@registrar.errors.full_messages.should match_array([])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should validates uniqueness of code' do
|
||||||
|
registrar = Fabricate.build(:registrar, code: @registrar.code)
|
||||||
|
registrar.valid?
|
||||||
|
registrar.errors.full_messages.should match_array([
|
||||||
|
'Code has already been taken'
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
it 'should have one version' do
|
it 'should have one version' do
|
||||||
with_versioning do
|
with_versioning do
|
||||||
@registrar.versions.should == []
|
@registrar.versions.should == []
|
||||||
|
@ -72,24 +80,12 @@ describe Registrar do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have code' do
|
it 'should have code' do
|
||||||
@registrar.code.should =~ /registrar/
|
@registrar.code.should =~ /REGISTRAR/
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to change code' do
|
it 'should not be able to change code' do
|
||||||
@registrar.code = 'not-updated'
|
@registrar.code = 'not-updated'
|
||||||
@registrar.code.should =~ /registrar/
|
@registrar.code.should =~ /REGISTRAR/
|
||||||
end
|
|
||||||
|
|
||||||
it 'should automatically add next code if original is taken' do
|
|
||||||
@registrar = Fabricate(:registrar, name: 'uniq')
|
|
||||||
@registrar.name = 'New name'
|
|
||||||
@registrar.code.should == 'uniq'
|
|
||||||
@registrar.save
|
|
||||||
|
|
||||||
@new_registrar = Fabricate.build(:registrar, name: 'uniq')
|
|
||||||
@new_registrar.valid?
|
|
||||||
@new_registrar.errors.full_messages.should == []
|
|
||||||
@new_registrar.code.should == 'uniq1'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to issue a prepayment invoice' do
|
it 'should be able to issue a prepayment invoice' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue