-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete all posts when the blog expires
Closes #4 This is the actual meat of the application. See https://github.com/collectiveidea/delayed_job/
- Loading branch information
Showing
5 changed files
with
44 additions
and
2 deletions.
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
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class SelfDestruct | ||
include ApplicationHelper | ||
|
||
def attempt | ||
if Time.current > expiration_time | ||
Rails.logger.fatal "[Self Destruct] Time expired, deleting all posts!" | ||
Post.destroy_all | ||
else | ||
Rails.logger.info "[Self Destruct] Time has not expired, cancelling self-destruct" | ||
end | ||
end | ||
end |
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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe SelfDestruct do | ||
describe "#attempt" do | ||
it "deletes all posts if it is after the expiration" do | ||
grace_period = ApplicationHelper::GRACE_PERIOD | ||
create(:post, created_at: (grace_period + 1.minute).ago) | ||
|
||
expect { SelfDestruct.new.attempt }.to change(Post, :count).from(1).to(0) | ||
end | ||
|
||
it "does not delete anything if it is before the expiration" do | ||
grace_period = ApplicationHelper::GRACE_PERIOD | ||
create(:post, created_at: (grace_period + 1.minute).ago) | ||
create(:post, created_at: (grace_period - 1.minute).ago) | ||
|
||
expect { SelfDestruct.new.attempt }.not_to change(Post, :count).from(2) | ||
end | ||
end | ||
end |