mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 22:24:47 +02:00
Merge pull request #1757 from internetee/1755-move-domain-delete-to-interactor
Move DomainDelete to interactor design pattern
This commit is contained in:
commit
c05795c9be
6 changed files with 64 additions and 12 deletions
9
app/interactions/domains/delete/base.rb
Normal file
9
app/interactions/domains/delete/base.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Domains
|
||||
module Delete
|
||||
class Base < ActiveInteraction::Base
|
||||
object :domain,
|
||||
class: Domain,
|
||||
description: 'Domain to delete'
|
||||
end
|
||||
end
|
||||
end
|
13
app/interactions/domains/delete/do_delete.rb
Normal file
13
app/interactions/domains/delete/do_delete.rb
Normal file
|
@ -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
|
14
app/interactions/domains/delete/notify_registrar.rb
Normal file
14
app/interactions/domains/delete/notify_registrar.rb
Normal file
|
@ -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
|
|
@ -3,15 +3,6 @@ class DomainDeleteJob < Que::Job
|
|||
def run(domain_id)
|
||||
domain = Domain.find(domain_id)
|
||||
|
||||
::PaperTrail.request.whodunnit = "job - #{self.class.name}"
|
||||
WhoisRecord.where(domain_id: domain.id).destroy_all
|
||||
|
||||
domain.destroy
|
||||
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
|
||||
)
|
||||
Domains::Delete::DoDelete.run(domain: domain)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,6 @@ module Concerns::Domain::Deletable
|
|||
end
|
||||
|
||||
def deletion_deadline
|
||||
delete_date + 24.hours
|
||||
(delete_date || Time.zone.now) + 24.hours
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainDeleteTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
end
|
||||
|
||||
def test_discards_domains_with_past_delete_date
|
||||
@domain.update!(delete_date: '2010-07-04')
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
|
||||
Domains::Delete::DoDelete.run(domain: @domain)
|
||||
|
||||
assert @domain.destroyed?
|
||||
end
|
||||
|
||||
def test_sends_notification
|
||||
@domain.update!(delete_date: '2010-07-04')
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
|
||||
assert_difference '@domain.registrar.notifications.count', 1 do
|
||||
Domains::Delete::DoDelete.run(domain: @domain)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue