From c3c1619238cee5f259f79001c5113cbc713d9d74 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Fri, 15 Jun 2018 14:45:30 +0300 Subject: [PATCH 1/6] Fix rubocop array issue --- .../registrant/domain_update_confirms_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/registrant/domain_update_confirms_controller.rb b/app/controllers/registrant/domain_update_confirms_controller.rb index ca91f0192..0d23943c9 100644 --- a/app/controllers/registrant/domain_update_confirms_controller.rb +++ b/app/controllers/registrant/domain_update_confirms_controller.rb @@ -1,6 +1,6 @@ class Registrant::DomainUpdateConfirmsController < RegistrantController - skip_before_action :authenticate_user!, only: [:show, :update] - skip_authorization_check only: [:show, :update] + skip_before_action :authenticate_user!, only: %i[show update] + skip_authorization_check only: %i[show update] def show return if params[:confirmed] || params[:rejected] From 657affb68d7949ed68fecffd57d62d22ab91a5d3 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Mon, 18 Jun 2018 10:54:05 +0300 Subject: [PATCH 2/6] Add whois record fixture and fix invoices fixture --- test/fixtures/invoices.yml | 1 - test/fixtures/whois_records.yml | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/whois_records.yml diff --git a/test/fixtures/invoices.yml b/test/fixtures/invoices.yml index 71189f6b6..6b9359343 100644 --- a/test/fixtures/invoices.yml +++ b/test/fixtures/invoices.yml @@ -35,5 +35,4 @@ overdue: for_payments_test: <<: *DEFAULTS total: 12.00 - id: 1 number: 1 diff --git a/test/fixtures/whois_records.yml b/test/fixtures/whois_records.yml new file mode 100644 index 000000000..0cdd25431 --- /dev/null +++ b/test/fixtures/whois_records.yml @@ -0,0 +1,6 @@ +shop: + name: shop.test + domain: shop + body: WHOIS text + json: + name: shop.test From 934404036f6c0948543ce32263a0cc9db3ccee4c Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Fri, 22 Jun 2018 13:38:47 +0300 Subject: [PATCH 3/6] Add tests for DomainUpdateConfirmJob --- test/jobs/domain_update_confirm_job_test.rb | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/jobs/domain_update_confirm_job_test.rb diff --git a/test/jobs/domain_update_confirm_job_test.rb b/test/jobs/domain_update_confirm_job_test.rb new file mode 100644 index 000000000..c507e2c98 --- /dev/null +++ b/test/jobs/domain_update_confirm_job_test.rb @@ -0,0 +1,36 @@ +require "test_helper" + +class DomainUpdateConfirmJobTest < ActiveSupport::TestCase + def setup + super + + @domain = domains(:shop) + @new_registrant = contacts(:william) + @user = users(:api_bestnames) + + @domain.update!(pending_json: { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id }) + end + + def teardown + super + end + + def test_rejected_registrant_verification_polls_a_message + DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED) + + last_registrar_message = @domain.registrar.messages.last + assert_equal(last_registrar_message.attached_obj_id, @domain.id) + assert_equal(last_registrar_message.body, 'Registrant rejected domain update: shop.test') + end + + def test_accepted_registrant_verification_polls_a_message + DomainUpdateConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED) + + last_registrar_message = @domain.registrar.messages.last + assert_equal(last_registrar_message.attached_obj_id, @domain.id) + assert_equal(last_registrar_message.body, 'Registrant confirmed domain update: shop.test') + end +end From 417a390ff7298da0c617a78f7e662ef5198420e4 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Mon, 25 Jun 2018 16:14:36 +0300 Subject: [PATCH 4/6] Add tests for DomainDeleteConfirmJob --- test/jobs/domain_delete_confirm_job_test.rb | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/jobs/domain_delete_confirm_job_test.rb diff --git a/test/jobs/domain_delete_confirm_job_test.rb b/test/jobs/domain_delete_confirm_job_test.rb new file mode 100644 index 000000000..9127ca628 --- /dev/null +++ b/test/jobs/domain_delete_confirm_job_test.rb @@ -0,0 +1,36 @@ +require "test_helper" + +class DomainDeleteConfirmJobTest < ActiveSupport::TestCase + def setup + super + + @domain = domains(:shop) + @new_registrant = contacts(:william) + @user = users(:api_bestnames) + + @domain.update!(pending_json: { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id }) + end + + def teardown + super + end + + def test_rejected_registrant_verification_polls_a_message + DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::REJECTED) + + last_registrar_message = @domain.registrar.messages.last + assert_equal(last_registrar_message.attached_obj_id, @domain.id) + assert_equal(last_registrar_message.body, 'Registrant rejected domain deletion: shop.test') + end + + def test_accepted_registrant_verification_polls_a_message + DomainDeleteConfirmJob.enqueue(@domain.id, RegistrantVerification::CONFIRMED) + + last_registrar_message = @domain.registrar.messages.last + assert_equal(last_registrar_message.attached_obj_id, @domain.id) + assert_equal(last_registrar_message.body, 'Registrant confirmed domain deletion: shop.test') + end +end From a8884b0545f41460643a4ce5acd794a676c60e47 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 26 Jun 2018 10:03:17 +0300 Subject: [PATCH 5/6] Remove duplicate rspec tests --- .../domain_delete_confirm_email_job_spec.rb | 40 ------------------- spec/jobs/domain_update_confirm_job_spec.rb | 18 --------- 2 files changed, 58 deletions(-) delete mode 100644 spec/jobs/domain_delete_confirm_email_job_spec.rb delete mode 100644 spec/jobs/domain_update_confirm_job_spec.rb diff --git a/spec/jobs/domain_delete_confirm_email_job_spec.rb b/spec/jobs/domain_delete_confirm_email_job_spec.rb deleted file mode 100644 index 0b2a0a6b7..000000000 --- a/spec/jobs/domain_delete_confirm_email_job_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'rails_helper' - -RSpec.describe DomainDeleteConfirmEmailJob do - describe '#run' do - let(:domain) { instance_double(Domain) } - let(:message) { instance_double(ActionMailer::MessageDelivery) } - - before :example do - expect(Domain).to receive(:find).and_return(domain) - allow(domain).to receive_messages( - id: 1, - name: 'test.com', - registrant_email: 'registrant@test.com', - registrar: 'registrar', - registrant: 'registrant') - end - - after :example do - domain_id = 1 - described_class.enqueue(domain_id) - end - - it 'creates log record' do - log_message = 'Send DomainDeleteMailer#confirm email for domain test.com (#1) to registrant@test.com' - - allow(DomainDeleteMailer).to receive(:confirm).and_return(message) - allow(message).to receive(:deliver_now) - - expect(Rails.logger).to receive(:info).with(log_message) - end - - it 'sends email' do - expect(DomainDeleteMailer).to receive(:confirm).with(domain: domain, - registrar: 'registrar', - registrant: 'registrant') - .and_return(message) - expect(message).to receive(:deliver_now) - end - end -end diff --git a/spec/jobs/domain_update_confirm_job_spec.rb b/spec/jobs/domain_update_confirm_job_spec.rb deleted file mode 100644 index 4748ca021..000000000 --- a/spec/jobs/domain_update_confirm_job_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'rails_helper' - -RSpec.describe DomainUpdateConfirmJob do - let(:domain) { instance_spy(Epp::Domain, registrant: registrant, errors: []) } - let(:registrant) { instance_double(Registrant) } - let(:registrant_change) { instance_spy(RegistrantChange) } - - it 'confirms registrant change' do - expect(Epp::Domain).to receive(:find).and_return(domain) - expect(RegistrantChange).to receive(:new) - .with(domain: domain, old_registrant: registrant) - .and_return(registrant_change) - - described_class.enqueue(domain_id = nil, action = RegistrantVerification::CONFIRMED) - - expect(registrant_change).to have_received(:confirm) - end -end From 8fb3d511c27791cb9f8c343817fb7820013a9d18 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 26 Jun 2018 11:37:31 +0300 Subject: [PATCH 6/6] Remove clean_pendings_lowlevel method --- app/jobs/domain_update_confirm_job.rb | 4 +++- app/models/domain.rb | 30 --------------------------- app/models/domain_cron.rb | 5 ++++- 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/app/jobs/domain_update_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb index b4d2a9f57..c661c7b6b 100644 --- a/app/jobs/domain_update_confirm_job.rb +++ b/app/jobs/domain_update_confirm_job.rb @@ -23,7 +23,9 @@ class DomainUpdateConfirmJob < Que::Job registrant: domain.registrant).deliver_now domain.poll_message!(:poll_pending_update_rejected_by_registrant) - domain.clean_pendings_lowlevel + + domain.preclean_pendings + domain.clean_pendings! end destroy # it's best to destroy the job in the same transaction end diff --git a/app/models/domain.rb b/app/models/domain.rb index 0f3afed90..30ed0b580 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -294,36 +294,6 @@ class Domain < ActiveRecord::Base save end - - # state changes may be done low-level - no validation - # in this metod we still save PaperTrail log. - def clean_pendings_lowlevel - statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION) - statuses.delete(DomainStatus::PENDING_UPDATE) - statuses.delete(DomainStatus::PENDING_DELETE) - - status_notes[DomainStatus::PENDING_UPDATE] = '' - status_notes[DomainStatus::PENDING_DELETE] = '' - - hash = { - registrant_verification_token: nil, - registrant_verification_asked_at: nil, - pending_json: {}, - status_notes: status_notes, - statuses: statuses.presence || [DomainStatus::OK], - # need this column in order to update PaperTrail version properly - updated_at: Time.now.utc - } - - # PaperTrail - self.attributes = hash - record_update - clear_version_instance! - reset_transaction_id - - update_columns(hash) - end - def pending_update! return true if pending_update? self.epp_pending_update = true # for epp diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index 80bf32c5a..8de52b226 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -21,7 +21,10 @@ class DomainCron if domain.pending_delete? || domain.pending_delete_confirmation? DomainMailer.pending_delete_expired_notification(domain.id, true).deliver end - domain.clean_pendings_lowlevel + + domain.preclean_pendings + domain.clean_pendings! + unless Rails.env.test? STDOUT << "#{Time.zone.now.utc} DomainCron.clean_expired_pendings: ##{domain.id} (#{domain.name})\n" end