mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
parent
ee30c8d4ef
commit
7f308d4123
5 changed files with 73 additions and 0 deletions
|
@ -57,6 +57,7 @@ class Domain < ApplicationRecord
|
||||||
|
|
||||||
has_many :legal_documents, as: :documentable
|
has_many :legal_documents, as: :documentable
|
||||||
accepts_nested_attributes_for :legal_documents, reject_if: proc { |attrs| attrs[:body].blank? }
|
accepts_nested_attributes_for :legal_documents, reject_if: proc { |attrs| attrs[:body].blank? }
|
||||||
|
has_many :registrant_verifications, dependent: :destroy
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
self.pending_json = {} if pending_json.blank?
|
self.pending_json = {} if pending_json.blank?
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Used in Registrant portal to collect registrant verifications
|
# Used in Registrant portal to collect registrant verifications
|
||||||
# Registrant postgres user can access this table directly.
|
# Registrant postgres user can access this table directly.
|
||||||
class RegistrantVerification < ApplicationRecord
|
class RegistrantVerification < ApplicationRecord
|
||||||
|
has_paper_trail
|
||||||
|
|
||||||
# actions
|
# actions
|
||||||
CONFIRMED = 'confirmed'
|
CONFIRMED = 'confirmed'
|
||||||
REJECTED = 'rejected'
|
REJECTED = 'rejected'
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
namespace :data_migrations do
|
||||||
|
task delete_orphaned_registrant_verifications: :environment do
|
||||||
|
orphaned_registrant_verifications = RegistrantVerification.where.not(domain_id: Domain.ids)
|
||||||
|
orphaned_registrant_verification_count = orphaned_registrant_verifications.count
|
||||||
|
processed_registrant_verification_count = 0
|
||||||
|
|
||||||
|
orphaned_registrant_verifications.each do |registrant_verification|
|
||||||
|
registrant_verification.destroy!
|
||||||
|
processed_registrant_verification_count += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Processed: #{processed_registrant_verification_count} out of" \
|
||||||
|
" #{orphaned_registrant_verification_count}"
|
||||||
|
end
|
||||||
|
end
|
12
test/models/registrant_verification_test.rb
Normal file
12
test/models/registrant_verification_test.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class RegistrantVerificationTest < ActiveSupport::TestCase
|
||||||
|
def test_audit_log
|
||||||
|
registrant_verification = registrant_verifications(:one)
|
||||||
|
random_action = "random#{rand(100)}"
|
||||||
|
|
||||||
|
assert_difference -> { PaperTrail::Version.count } do
|
||||||
|
registrant_verification.update_attributes!(action: random_action)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,43 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ArchiveOrphanedRegistrantVerificationsTest < ActiveSupport::TestCase
|
||||||
|
def test_deletes_orphaned_registrant_verifications
|
||||||
|
create_orphaned_registrant_verification
|
||||||
|
|
||||||
|
assert_difference 'RegistrantVerification.count', -1 do
|
||||||
|
capture_io do
|
||||||
|
run_task
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_keeps_non_orphaned_registrant_verifications_intact
|
||||||
|
assert_no_difference 'RegistrantVerification.count' do
|
||||||
|
capture_io do
|
||||||
|
run_task
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_output
|
||||||
|
create_orphaned_registrant_verification
|
||||||
|
|
||||||
|
assert_output "Processed: 1 out of 1\n" do
|
||||||
|
run_task
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def create_orphaned_registrant_verification
|
||||||
|
non_existent_domain_id = 55
|
||||||
|
assert_not_includes Domain.ids, non_existent_domain_id
|
||||||
|
|
||||||
|
RegistrantVerification.connection.disable_referential_integrity do
|
||||||
|
registrant_verifications(:one).update_columns(domain_id: non_existent_domain_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_task
|
||||||
|
Rake::Task['data_migrations:delete_orphaned_registrant_verifications'].execute end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue