-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a spec to test the access_logs:cleanup task
- Loading branch information
1 parent
24212cb
commit 815c129
Showing
2 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |