-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up unconfirmed users that have been created more than 2 weeks ago
These users have been sent an email with a link to confirm their account but have not accepted it
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace :cleanup do | ||
desc "Clean up inactive unconfirmed users" | ||
task unconfirmed: :environment do | ||
UseCases::DeleteInactiveUnconfirmed.execute(2.weeks) | ||
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,7 @@ | ||
module UseCases | ||
class DeleteInactiveUnconfirmed | ||
def self.execute(inactive_period) | ||
User.unconfirmed.where("created_at < ?", Time.zone.now - inactive_period).delete_all | ||
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,39 @@ | ||
describe UseCases::DeleteInactiveUnconfirmed do | ||
subject { UseCases::DeleteInactiveUnconfirmed } | ||
let(:inactive_period) { 2.weeks } | ||
describe "There are no unconfirmed users" do | ||
before do | ||
create(:user) | ||
end | ||
it "does not delete any users" do | ||
expect { subject.execute(inactive_period) }.to_not change(User, :count) | ||
end | ||
end | ||
describe "There is an inactive unconfirmed user who has been inactive for less than the specified period" do | ||
before do | ||
create(:user, :unconfirmed, created_at: 1.week.ago).id | ||
end | ||
it "does not delete any users" do | ||
expect { subject.execute(inactive_period) }.to_not change(User, :count) | ||
end | ||
end | ||
describe "There is an unconfirmed user who has been inactive for more than the specified period" do | ||
before do | ||
@inactive_user_id = create(:user, :unconfirmed, created_at: 3.weeks.ago).id | ||
end | ||
it "deletes the unconfirmed user" do | ||
subject.execute(inactive_period) | ||
expect(User.where(id: @inactive_user_id)).to_not exist | ||
end | ||
end | ||
describe "There is a mix of unconfirmed and unconfirmed users" do | ||
before do | ||
create_list(:user, 2, :unconfirmed, created_at: 1.week.ago) | ||
create_list(:user, 3, :unconfirmed, created_at: 3.weeks.ago) | ||
create_list(:user, 7, created_at: 3.weeks.ago) | ||
end | ||
it "deletes the inactive unconfirmed users only" do | ||
expect { subject.execute(inactive_period) }.to change(User, :count).by(-3) | ||
end | ||
end | ||
end |