From bbbb3d5367bcfa7700338d08955ecb1358d65d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 3 Sep 2020 16:42:04 +0300 Subject: [PATCH] Improve logging --- app/models/concerns/contact/archivable.rb | 7 +------ app/models/inactive_contacts.rb | 8 +------- lib/tasks/contacts/archive.rake | 1 - test/models/inactive_contacts_test.rb | 6 ++++-- test/tasks/contacts/archive_test.rb | 3 ++- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/app/models/concerns/contact/archivable.rb b/app/models/concerns/contact/archivable.rb index 6e4edb958..8218dedaf 100644 --- a/app/models/concerns/contact/archivable.rb +++ b/app/models/concerns/contact/archivable.rb @@ -12,7 +12,7 @@ module Concerns def archivable?(post: false) inactive = inactive? - log("Found archivable contact id(#{id}), code (#{code})") if inactive && !post + puts "Found archivable contact id(#{id}), code (#{code})" if inactive && !post inactive end @@ -38,11 +38,6 @@ module Concerns def inactivity_period Setting.orphans_contacts_in_months.months end - - def log(msg) - @logger ||= Logger.new(STDOUT) - @logger.info(msg) - end end end end diff --git a/app/models/inactive_contacts.rb b/app/models/inactive_contacts.rb index 0899a751f..a5218950d 100644 --- a/app/models/inactive_contacts.rb +++ b/app/models/inactive_contacts.rb @@ -7,15 +7,9 @@ class InactiveContacts def archive(verified: false) contacts.each do |contact| - log("Archiving contact: id(#{contact.id}), code(#{contact.code})") - + puts "Archiving contact: id(#{contact.id}), code(#{contact.code})" contact.archive(verified: verified) yield contact if block_given? end end - - def log(msg) - @logger ||= Logger.new(STDOUT) - @logger.info(msg) - end end diff --git a/lib/tasks/contacts/archive.rake b/lib/tasks/contacts/archive.rake index 6eb23b0b7..76921b1f9 100644 --- a/lib/tasks/contacts/archive.rake +++ b/lib/tasks/contacts/archive.rake @@ -2,7 +2,6 @@ namespace :contacts do desc 'Archives inactive contacts' task archive: :environment do - puts 'Starting to gather archivable contacts' inactive_contacts = InactiveContacts.new archived_contacts = inactive_contacts.archive(verified: true) diff --git a/test/models/inactive_contacts_test.rb b/test/models/inactive_contacts_test.rb index eb0d23b3b..a88be5350 100644 --- a/test/models/inactive_contacts_test.rb +++ b/test/models/inactive_contacts_test.rb @@ -3,11 +3,13 @@ require 'test_helper' class InactiveContactsTest < ActiveSupport::TestCase def test_archives_inactive_contacts contact_mock = Minitest::Mock.new - contact_mock.expect(:archive, nil) + contact_mock.expect(:archive, nil, [{verified: false}]) + contact_mock.expect(:id, 'id') + contact_mock.expect(:code, 'code') inactive_contacts = InactiveContacts.new([contact_mock]) inactive_contacts.archive assert_mock contact_mock end -end \ No newline at end of file +end diff --git a/test/tasks/contacts/archive_test.rb b/test/tasks/contacts/archive_test.rb index 7120d2449..9336ad265 100644 --- a/test/tasks/contacts/archive_test.rb +++ b/test/tasks/contacts/archive_test.rb @@ -13,7 +13,8 @@ class ArchiveContactsTaskTest < ActiveSupport::TestCase contact = archivable_contact eliminate_effect_of_all_contacts_except(contact) - expected_output = "Contact ##{contact.id} (code: #{contact.code}) is archived\n" \ + expected_output = "Found archivable contact id(#{contact.id}), code (#{contact.code})\n" \ + "Archiving contact: id(#{contact.id}), code(#{contact.code})\n" \ "Archived total: 1\n" assert_output(expected_output) { run_task } end