Reference orphans_contacts_in_months directly from Settings

This commit is contained in:
Karl Erik Õunapuu 2020-09-03 12:41:44 +03:00
parent 6707ca17bf
commit 28dea2f13c
No known key found for this signature in database
GPG key ID: C9DD647298A34764
3 changed files with 9 additions and 10 deletions

View file

@ -3,11 +3,6 @@ module Concerns
module Archivable module Archivable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do
class_attribute :inactivity_period, instance_predicate: false, instance_writer: false
self.inactivity_period = Setting.orphans_contacts_in_months.months
end
class_methods do class_methods do
def archivable def archivable
unlinked.find_each.select(&:archivable?) unlinked.find_each.select(&:archivable?)
@ -33,6 +28,10 @@ module Concerns
DomainVersion.was_contact_linked?(id) ? false : created_at <= inactivity_period.ago DomainVersion.was_contact_linked?(id) ? false : created_at <= inactivity_period.ago
end end
def inactivity_period
Setting.orphans_contacts_in_months.months
end
end end
end end
end end

View file

@ -14,7 +14,7 @@ class ArchivableContactTest < ActiveSupport::TestCase
end end
def test_contact_is_archivable_when_it_was_never_linked_and_inactivity_period_has_passed def test_contact_is_archivable_when_it_was_never_linked_and_inactivity_period_has_passed
Contact.inactivity_period = 1.second Setting.orphans_contacts_in_months = 0
@contact.created_at = Time.zone.parse('2010-07-05 00:00:00') @contact.created_at = Time.zone.parse('2010-07-05 00:00:00')
travel_to Time.zone.parse('2010-07-05 00:00:01') travel_to Time.zone.parse('2010-07-05 00:00:01')
@ -24,7 +24,7 @@ class ArchivableContactTest < ActiveSupport::TestCase
end end
def test_contact_is_not_archivable_when_it_was_never_linked_and_inactivity_period_has_not_passed def test_contact_is_not_archivable_when_it_was_never_linked_and_inactivity_period_has_not_passed
Contact.inactivity_period = 1.second Setting.orphans_contacts_in_months = 5
@contact.created_at = Time.zone.parse('2010-07-05') @contact.created_at = Time.zone.parse('2010-07-05')
travel_to Time.zone.parse('2010-07-05') travel_to Time.zone.parse('2010-07-05')
@ -62,7 +62,7 @@ class ArchivableContactTest < ActiveSupport::TestCase
def archivable_contact def archivable_contact
contact = contacts(:john) contact = contacts(:john)
Contact.inactivity_period = 0.seconds Setting.orphans_contacts_in_months = 0
DomainVersion.delete_all DomainVersion.delete_all
other_contact = contacts(:william) other_contact = contacts(:william)
@ -75,7 +75,7 @@ class ArchivableContactTest < ActiveSupport::TestCase
end end
def unarchivable_contact def unarchivable_contact
Contact.inactivity_period = 99.years Setting.orphans_contacts_in_months = 1188
@contact @contact
end end
end end

View file

@ -22,7 +22,7 @@ class ArchiveContactsTaskTest < ActiveSupport::TestCase
def archivable_contact def archivable_contact
contact = contacts(:john) contact = contacts(:john)
Contact.inactivity_period = 0.seconds Setting.orphans_contacts_in_months = 0
DomainVersion.delete_all DomainVersion.delete_all
other_contact = contacts(:william) other_contact = contacts(:william)