diff --git a/app/jobs/base.rb b/app/jobs/base.rb index fc7b3c99489..102d1e8e081 100644 --- a/app/jobs/base.rb +++ b/app/jobs/base.rb @@ -130,7 +130,7 @@ module Jobs def self.logger @@logger ||= begin - File.touch(log_path) if !File.exist?(log_path) + FileUtils.touch(log_path) if !File.exist?(log_path) Logger.new(log_path) end end diff --git a/spec/jobs/jobs_base_spec.rb b/spec/jobs/jobs_base_spec.rb index a6110ac61e2..42630bf13a2 100644 --- a/spec/jobs/jobs_base_spec.rb +++ b/spec/jobs/jobs_base_spec.rb @@ -150,24 +150,24 @@ RSpec.describe ::Jobs::Base do end context "when `Discourse.enable_sidekiq_logging?` is `true`" do - let(:tmp_log_file) { Tempfile.new("sidekiq.log") } + let(:tmp_log_file_path) { "#{Rails.root}/tmp/sidekiq_test_log.log" } before do Discourse.enable_sidekiq_logging - described_class::JobInstrumenter.set_log_path(tmp_log_file.path) + described_class::JobInstrumenter.set_log_path(tmp_log_file_path) end after do Discourse.disable_sidekiq_logging described_class::JobInstrumenter.reset_log_path - tmp_log_file.close + FileUtils.rm(tmp_log_file_path) end it "should log the job in the sidekiq log file" do job = GoodJob.new job.perform({ some_param: "some_value" }) - parsed_logline = JSON.parse(File.read(tmp_log_file.path).split("\n").first) + parsed_logline = JSON.parse(File.read(tmp_log_file_path).split("\n").first) expect(parsed_logline["hostname"]).to be_present expect(parsed_logline["pid"]).to be_present