Skip to content

Commit

Permalink
Add a spec to test the access_logs:cleanup task
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyprivett committed Nov 15, 2024
1 parent 24212cb commit 815c129
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/factories/access_logs.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FactoryBot.define do
factory :access_log do
id { '35cc6a19-0d88-453a-a0cb-970e161b5cbb' }
request_id { 'b68c0883-540c-426a-a9a4-daf586eb5c78' }
timestamp { Time.zone.now }
whodunnit { 'AUSER01' }
Expand Down
28 changes: 28 additions & 0 deletions spec/lib/tasks/access_logs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Rake::Task['access_logs:cleanup'] do
before do
# 2 access_logs to retain
create(:access_log, timestamp: 1.month.ago)
create(:access_log, timestamp: 2.months.ago)

# 3 access_logs to delete
create(:access_log, timestamp: 7.months.ago)
create(:access_log, timestamp: 8.months.ago)
create(:access_log, timestamp: 9.months.ago)

allow($stdout).to receive(:puts)

described_class.invoke
end

it 'cleans up the access_logs and writes to stdout' do
expect(AccessLog.count).to eq(2)

expect($stdout)
.to have_received(:puts)
.with('Cleaning up 3 access_logs in 1 iterations')
end
end

0 comments on commit 815c129

Please sign in to comment.