From d5f8f0795650286dcee39c3822211000ad077268 Mon Sep 17 00:00:00 2001 From: mmeest Date: Tue, 1 Jul 2025 12:08:03 +0300 Subject: [PATCH] added new test --- test/models/contact/archivable_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/models/contact/archivable_test.rb b/test/models/contact/archivable_test.rb index cd07d3894..02d209f08 100644 --- a/test/models/contact/archivable_test.rb +++ b/test/models/contact/archivable_test.rb @@ -68,6 +68,30 @@ class ArchivableContactTest < ActiveSupport::TestCase registrar.notifications.last.text) end + def test_write_to_registrar_log_creates_log_file + contact = archivable_contact + registrar = contact.registrar + log_dir = '/tmp/test_logs' + ENV['contact_archivation_log_file_dir'] = log_dir + + # Using Stub to avoid creating the log file in the filesystem + FileUtils.stub(:mkdir_p, true) do + file_mock = Minitest::Mock.new + + file_mock.expect(:write, nil) do |arg| + arg.to_s.include?(contact.code) + end + + file_mock.expect(:close, nil) + + File.stub(:new, file_mock) do + contact.archive(extra_log: true, verified: true, notify: false) + end + + assert_mock file_mock + end + end + private def archivable_contact