From 30ddf83ee42dd21cc4cfc77a6addadda4a6ea16f Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 30 Nov 2020 16:20:24 +0500 Subject: [PATCH] Move interactor to namespace --- app/interactions/domain_delete_interaction/base.rb | 7 ------- .../domain_delete_interaction/delete.rb | 11 ----------- .../domain_delete_interaction/notify_registrar.rb | 12 ------------ app/interactions/domains/delete/base.rb | 9 +++++++++ app/interactions/domains/delete/do_delete.rb | 13 +++++++++++++ .../domains/delete/notify_registrar.rb | 14 ++++++++++++++ app/jobs/domain_delete_job.rb | 2 +- ...action_delete_test.rb => domain_delete_test.rb} | 6 +++--- 8 files changed, 40 insertions(+), 34 deletions(-) delete mode 100644 app/interactions/domain_delete_interaction/base.rb delete mode 100644 app/interactions/domain_delete_interaction/delete.rb delete mode 100644 app/interactions/domain_delete_interaction/notify_registrar.rb create mode 100644 app/interactions/domains/delete/base.rb create mode 100644 app/interactions/domains/delete/do_delete.rb create mode 100644 app/interactions/domains/delete/notify_registrar.rb rename test/interactions/domain_delete_interaction/{domain_delete_interaction_delete_test.rb => domain_delete_test.rb} (71%) diff --git a/app/interactions/domain_delete_interaction/base.rb b/app/interactions/domain_delete_interaction/base.rb deleted file mode 100644 index b2895e1d1..000000000 --- a/app/interactions/domain_delete_interaction/base.rb +++ /dev/null @@ -1,7 +0,0 @@ -module DomainDeleteInteraction - class Base < ActiveInteraction::Base - object :domain, - class: Domain, - description: 'Domain to delete' - end -end diff --git a/app/interactions/domain_delete_interaction/delete.rb b/app/interactions/domain_delete_interaction/delete.rb deleted file mode 100644 index 1a74aae50..000000000 --- a/app/interactions/domain_delete_interaction/delete.rb +++ /dev/null @@ -1,11 +0,0 @@ -module DomainDeleteInteraction - class Delete < Base - def execute - ::PaperTrail.request.whodunnit = "interaction - #{self.class.name}" - WhoisRecord.where(domain_id: domain.id).destroy_all - - domain.destroy - compose(DomainDeleteInteraction::NotifyRegistrar, inputs) - end - end -end diff --git a/app/interactions/domain_delete_interaction/notify_registrar.rb b/app/interactions/domain_delete_interaction/notify_registrar.rb deleted file mode 100644 index 990f74de6..000000000 --- a/app/interactions/domain_delete_interaction/notify_registrar.rb +++ /dev/null @@ -1,12 +0,0 @@ -module DomainDeleteInteraction - class NotifyRegistrar < Base - def execute - bye_bye = domain.versions.last - domain.registrar.notifications.create!( - text: "#{I18n.t(:domain_deleted)}: #{domain.name}", - attached_obj_id: bye_bye.id, - attached_obj_type: bye_bye.class.to_s - ) - end - end -end diff --git a/app/interactions/domains/delete/base.rb b/app/interactions/domains/delete/base.rb new file mode 100644 index 000000000..434712f72 --- /dev/null +++ b/app/interactions/domains/delete/base.rb @@ -0,0 +1,9 @@ +module Domains + module Delete + class Base < ActiveInteraction::Base + object :domain, + class: Domain, + description: 'Domain to delete' + end + end +end diff --git a/app/interactions/domains/delete/do_delete.rb b/app/interactions/domains/delete/do_delete.rb new file mode 100644 index 000000000..202c36938 --- /dev/null +++ b/app/interactions/domains/delete/do_delete.rb @@ -0,0 +1,13 @@ +module Domains + module Delete + class DoDelete < Base + def execute + ::PaperTrail.request.whodunnit = "interaction - #{self.class.name}" + WhoisRecord.where(domain_id: domain.id).destroy_all + + domain.destroy + compose(Domains::Delete::NotifyRegistrar, inputs) + end + end + end +end diff --git a/app/interactions/domains/delete/notify_registrar.rb b/app/interactions/domains/delete/notify_registrar.rb new file mode 100644 index 000000000..d6af00fd8 --- /dev/null +++ b/app/interactions/domains/delete/notify_registrar.rb @@ -0,0 +1,14 @@ +module Domains + module Delete + class NotifyRegistrar < Base + def execute + bye_bye = domain.versions.last + domain.registrar.notifications.create!( + text: "#{I18n.t(:domain_deleted)}: #{domain.name}", + attached_obj_id: bye_bye.id, + attached_obj_type: bye_bye.class.to_s + ) + end + end + end +end diff --git a/app/jobs/domain_delete_job.rb b/app/jobs/domain_delete_job.rb index 49ef23aa3..5577908c6 100644 --- a/app/jobs/domain_delete_job.rb +++ b/app/jobs/domain_delete_job.rb @@ -3,6 +3,6 @@ class DomainDeleteJob < Que::Job def run(domain_id) domain = Domain.find(domain_id) - DomainDeleteInteraction::Delete.run(domain: domain) + Domains::Delete::DoDelete.run(domain: domain) end end diff --git a/test/interactions/domain_delete_interaction/domain_delete_interaction_delete_test.rb b/test/interactions/domain_delete_interaction/domain_delete_test.rb similarity index 71% rename from test/interactions/domain_delete_interaction/domain_delete_interaction_delete_test.rb rename to test/interactions/domain_delete_interaction/domain_delete_test.rb index a44140b34..9582fae03 100644 --- a/test/interactions/domain_delete_interaction/domain_delete_interaction_delete_test.rb +++ b/test/interactions/domain_delete_interaction/domain_delete_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class DomainDeleteInteractionDeleteTest < ActiveSupport::TestCase +class DomainDeleteTest < ActiveSupport::TestCase setup do @domain = domains(:shop) end @@ -9,7 +9,7 @@ class DomainDeleteInteractionDeleteTest < ActiveSupport::TestCase @domain.update!(delete_date: '2010-07-04') travel_to Time.zone.parse('2010-07-05') - DomainDeleteInteraction::Delete.run(domain: @domain) + Domains::Delete::DoDelete.run(domain: @domain) assert @domain.destroyed? end @@ -19,7 +19,7 @@ class DomainDeleteInteractionDeleteTest < ActiveSupport::TestCase travel_to Time.zone.parse('2010-07-05') assert_difference '@domain.registrar.notifications.count', 1 do - DomainDeleteInteraction::Delete.run(domain: @domain) + Domains::Delete::DoDelete.run(domain: @domain) end end end