diff --git a/app/models/concerns/versions.rb b/app/models/concerns/versions.rb index bd6580adf5..c9735901b0 100644 --- a/app/models/concerns/versions.rb +++ b/app/models/concerns/versions.rb @@ -4,7 +4,13 @@ module Versions included do 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 before_create :add_creator diff --git a/app/models/contact.rb b/app/models/contact.rb index 9cb9544621..f5f41e2f76 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -14,8 +14,6 @@ class Contact < ApplicationRecord has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id' has_many :actions, dependent: :destroy - has_paper_trail class_name: "ContactVersion", meta: { children: :children_log } - attr_accessor :legal_document_id alias_attribute :kind, :ident_type alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail diff --git a/app/models/domain.rb b/app/models/domain.rb index b37d31ea0a..ceff9e8104 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -10,8 +10,6 @@ class Domain < ApplicationRecord include Concerns::Domain::RegistryLockable include Concerns::Domain::Releasable - has_paper_trail class_name: "DomainVersion", meta: { children: :children_log } - attr_accessor :roles attr_accessor :legal_document_id diff --git a/test/integration/api/registrant/registrant_api_registry_locks_test.rb b/test/integration/api/registrant/registrant_api_registry_locks_test.rb index e4f5510720..4babdf4286 100644 --- a/test/integration/api/registrant/registrant_api_registry_locks_test.rb +++ b/test/integration/api/registrant/registrant_api_registry_locks_test.rb @@ -25,7 +25,7 @@ def test_can_lock_a_not_locked_domain end 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', headers: @auth_headers end diff --git a/test/integration/contact/audit_log_test.rb b/test/integration/contact/audit_log_test.rb index 41eb74cdd0..41699d5958 100644 --- a/test/integration/contact/audit_log_test.rb +++ b/test/integration/contact/audit_log_test.rb @@ -5,7 +5,7 @@ def test_stores_metadata contact = contacts(:john) contact.legal_document_id = 1 - assert_difference 'contact.versions.count', 2 do + assert_difference 'contact.versions.count', 1 do contact.save! end diff --git a/test/integration/domain/audit_log_test.rb b/test/integration/domain/audit_log_test.rb index 244e55ff72..a17fded0db 100644 --- a/test/integration/domain/audit_log_test.rb +++ b/test/integration/domain/audit_log_test.rb @@ -14,7 +14,7 @@ def test_stores_metadata assert_equal registrant_id, domain.registrant_id domain.legal_document_id = legal_document_id - assert_difference 'domain.versions.count', 2 do + assert_difference 'domain.versions.count', 1 do domain.save! end diff --git a/test/learning/paper_trail_test.rb b/test/learning/paper_trail_test.rb index 1a46022e44..b7351c644b 100644 --- a/test/learning/paper_trail_test.rb +++ b/test/learning/paper_trail_test.rb @@ -21,6 +21,25 @@ def test_returns_version_list assert_respond_to @record.versions.first, :item_id 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 @record = Post.create!(title: 'old title') original_record = @record.clone diff --git a/test/models/domain/domain_version_test.rb b/test/models/domain/domain_version_test.rb index 305f353fac..74844f3afe 100644 --- a/test/models/domain/domain_version_test.rb +++ b/test/models/domain/domain_version_test.rb @@ -17,7 +17,7 @@ def test_assigns_creator_to_paper_trail_whodunnit duplicate_domain = prepare_duplicate_domain 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! end @@ -30,7 +30,7 @@ def test_assigns_creator_to_paper_trail_whodunnit def test_assigns_updator_to_paper_trail_whodunnit PaperTrail.whodunnit = @user.id_role_username - assert_difference '@domain.versions.count', 2 do + assert_difference '@domain.versions.count', 1 do @domain.apply_registry_lock end