From 5b4658b905cfa74d334255384f3284fea1ef2821 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 29 Sep 2017 00:39:25 +0300 Subject: [PATCH] Allow EPP contact:update with the same ident data as current one #569 --- app/models/epp/contact.rb | 6 +- .../requests/epp/contact/update/ident_spec.rb | 61 ++++++++++++------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 7548ee4ec..b280ceea6 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -158,7 +158,11 @@ class Epp::Contact < Contact # https://github.com/internetee/registry/issues/576 if ident_frame if identifier.valid? - report_valid_ident_error + submitted_ident = Ident.new(code: ident_frame.text, + type: ident_frame.attr('type'), + country_code: ident_frame.attr('cc')) + + report_valid_ident_error if submitted_ident != identifier else ident_update_attempt = ident_frame.text.present? && (ident_frame.text != ident) report_ident_update_error if ident_update_attempt diff --git a/spec/requests/epp/contact/update/ident_spec.rb b/spec/requests/epp/contact/update/ident_spec.rb index 6c016275a..c93ba6390 100644 --- a/spec/requests/epp/contact/update/ident_spec.rb +++ b/spec/requests/epp/contact/update/ident_spec.rb @@ -34,34 +34,51 @@ RSpec.describe 'EPP contact:update' do end context 'when contact ident is valid' do - let!(:contact) { create(:contact, code: 'TEST', ident: 'test', ident_type: 'priv', ident_country_code: 'US') } + context 'when submitted ident matches current one' do + let!(:contact) { create(:contact, code: 'TEST', + ident: 'test', + ident_type: 'priv', + ident_country_code: 'US') } - it 'does not update code' do - expect do + specify do request - contact.reload - end.to_not change { ident.code } + expect(epp_response).to have_result(:success) + end end - it 'does not update type' do - expect do + context 'when submitted ident does not match current one' do + let!(:contact) { create(:contact, code: 'TEST', + ident: 'another-test', + ident_type: 'priv', + ident_country_code: 'US') } + + it 'does not update code' do + expect do + request + contact.reload + end.to_not change { ident.code } + end + + it 'does not update type' do + expect do + request + contact.reload + end.to_not change { ident.type } + end + + it 'does not update country code' do + expect do + request + contact.reload + end.to_not change { ident.country_code } + end + + specify do request - contact.reload - end.to_not change { ident.type } - end - it 'does not update country code' do - expect do - request - contact.reload - end.to_not change { ident.country_code } - end - - specify do - request - - expect(epp_response).to have_result(:data_management_policy_violation, - t('epp.contacts.errors.valid_ident')) + expect(epp_response).to have_result(:data_management_policy_violation, + t('epp.contacts.errors.valid_ident')) + end end end