mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 07:34:45 +02:00
Fix double versioning on Domain & Contact models
This commit is contained in:
parent
bf67180bce
commit
a1651ca1b9
8 changed files with 31 additions and 10 deletions
|
@ -4,7 +4,13 @@ module Versions
|
||||||
|
|
||||||
included do
|
included do
|
||||||
attr_accessor :version_loader
|
attr_accessor :version_loader
|
||||||
has_paper_trail class_name: "#{model_name}Version"
|
WITH_CHILDREN = %w[Domain Contact].freeze
|
||||||
|
|
||||||
|
if WITH_CHILDREN.include?(model_name.name)
|
||||||
|
has_paper_trail class_name: "#{model_name}Version", meta: { children: :children_log }
|
||||||
|
else
|
||||||
|
has_paper_trail class_name: "#{model_name}Version"
|
||||||
|
end
|
||||||
|
|
||||||
# add creator and updator
|
# add creator and updator
|
||||||
before_create :add_creator
|
before_create :add_creator
|
||||||
|
|
|
@ -14,8 +14,6 @@ class Contact < ApplicationRecord
|
||||||
has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id'
|
has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id'
|
||||||
has_many :actions, dependent: :destroy
|
has_many :actions, dependent: :destroy
|
||||||
|
|
||||||
has_paper_trail class_name: "ContactVersion", meta: { children: :children_log }
|
|
||||||
|
|
||||||
attr_accessor :legal_document_id
|
attr_accessor :legal_document_id
|
||||||
alias_attribute :kind, :ident_type
|
alias_attribute :kind, :ident_type
|
||||||
alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail
|
alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail
|
||||||
|
|
|
@ -10,8 +10,6 @@ class Domain < ApplicationRecord
|
||||||
include Concerns::Domain::RegistryLockable
|
include Concerns::Domain::RegistryLockable
|
||||||
include Concerns::Domain::Releasable
|
include Concerns::Domain::Releasable
|
||||||
|
|
||||||
has_paper_trail class_name: "DomainVersion", meta: { children: :children_log }
|
|
||||||
|
|
||||||
attr_accessor :roles
|
attr_accessor :roles
|
||||||
|
|
||||||
attr_accessor :legal_document_id
|
attr_accessor :legal_document_id
|
||||||
|
|
|
@ -25,7 +25,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_locking_a_domain_creates_a_version_record
|
def test_locking_a_domain_creates_a_version_record
|
||||||
assert_difference '@domain.versions.count', 2 do
|
assert_difference '@domain.versions.count', 1 do
|
||||||
post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
|
post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
|
||||||
headers: @auth_headers
|
headers: @auth_headers
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ class ContactAuditLogTest < ActionDispatch::IntegrationTest
|
||||||
contact = contacts(:john)
|
contact = contacts(:john)
|
||||||
|
|
||||||
contact.legal_document_id = 1
|
contact.legal_document_id = 1
|
||||||
assert_difference 'contact.versions.count', 2 do
|
assert_difference 'contact.versions.count', 1 do
|
||||||
contact.save!
|
contact.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class DomainAuditLogTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal registrant_id, domain.registrant_id
|
assert_equal registrant_id, domain.registrant_id
|
||||||
domain.legal_document_id = legal_document_id
|
domain.legal_document_id = legal_document_id
|
||||||
|
|
||||||
assert_difference 'domain.versions.count', 2 do
|
assert_difference 'domain.versions.count', 1 do
|
||||||
domain.save!
|
domain.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,25 @@ class PaperTrailLearningTest < ActiveSupport::TestCase
|
||||||
assert_respond_to @record.versions.first, :item_id
|
assert_respond_to @record.versions.first, :item_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_returns_version_count_on_domains
|
||||||
|
@domain = domains(:airport)
|
||||||
|
@domain.save
|
||||||
|
|
||||||
|
assert_equal 1, @domain.versions.count
|
||||||
|
|
||||||
|
@domain.name = 'domain.test'
|
||||||
|
@domain.save!
|
||||||
|
assert_equal 2, @domain.versions.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_version_count_on_users
|
||||||
|
@user = users(:registrant)
|
||||||
|
|
||||||
|
@user.email = 'aaa@bbb.com'
|
||||||
|
@user.save!
|
||||||
|
assert_equal 1, @user.versions.count
|
||||||
|
end
|
||||||
|
|
||||||
def test_creates_new_version_upon_update
|
def test_creates_new_version_upon_update
|
||||||
@record = Post.create!(title: 'old title')
|
@record = Post.create!(title: 'old title')
|
||||||
original_record = @record.clone
|
original_record = @record.clone
|
||||||
|
|
|
@ -17,7 +17,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
||||||
duplicate_domain = prepare_duplicate_domain
|
duplicate_domain = prepare_duplicate_domain
|
||||||
|
|
||||||
PaperTrail.whodunnit = @user.id_role_username
|
PaperTrail.whodunnit = @user.id_role_username
|
||||||
assert_difference 'duplicate_domain.versions.count', 2 do
|
assert_difference 'duplicate_domain.versions.count', 1 do
|
||||||
duplicate_domain.save!
|
duplicate_domain.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class DomainVersionTest < ActiveSupport::TestCase
|
||||||
def test_assigns_updator_to_paper_trail_whodunnit
|
def test_assigns_updator_to_paper_trail_whodunnit
|
||||||
PaperTrail.whodunnit = @user.id_role_username
|
PaperTrail.whodunnit = @user.id_role_username
|
||||||
|
|
||||||
assert_difference '@domain.versions.count', 2 do
|
assert_difference '@domain.versions.count', 1 do
|
||||||
@domain.apply_registry_lock
|
@domain.apply_registry_lock
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue