-
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.
- Loading branch information
Showing
9 changed files
with
98 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module CleanupHelper | ||
def cleanup | ||
r = Event.where("end_date < ?", DateTime.now-1.day).destroy_all | ||
r.each do |event| | ||
Rails.logger.info "Deleted outdated event #{event.id} (#{event.name}) with #{event.entries.count} entries" | ||
end | ||
|
||
r = Entry.where("date < ?", DateTime.now-3.hours).destroy_all | ||
r.each do |entry| | ||
Rails.logger.info "Deleted outdated entry #{entry.id} (#{entry.event.name})" | ||
end | ||
|
||
r = Event.unconfirmed.where("created_at < ?", DateTime.now-1.day).destroy_all | ||
r.each do |event| | ||
Rails.logger.info "Deleted unconfirmed event #{event.id} (#{event.name})" | ||
end | ||
|
||
r = Entry.unconfirmed.where("created_at < ?", DateTime.now-1.day).destroy_all | ||
r.each do |entry| | ||
Rails.logger.info "Deleted unconfirmed entry #{entry.id} (#{entry.event.name})" | ||
end | ||
|
||
AltchaSolution.cleanup | ||
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
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 |
---|---|---|
@@ -1,4 +1,21 @@ | ||
#!/usr/bin/env ruby | ||
|
||
if ENV["RAILS_ENV"] == "test" | ||
require 'simplecov' | ||
|
||
SimpleCov.start :rails do | ||
add_filter "app/admin" | ||
add_filter "app/channels" | ||
add_filter "app/jobs" | ||
add_filter "app/models/concerns/" | ||
add_filter "config" | ||
add_filter "db" | ||
add_filter "lib/tasks" | ||
add_filter "test" | ||
add_filter "vendor" | ||
end | ||
end | ||
|
||
APP_PATH = File.expand_path("../config/application", __dir__) | ||
require_relative "../config/boot" | ||
require "rails/commands" |
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 |
---|---|---|
@@ -1,7 +1,45 @@ | ||
require "test_helper" | ||
|
||
class CleanupTest < ActionDispatch::IntegrationTest | ||
test "should run cleanup without errors" do | ||
test "should remove outdated events" do | ||
event = events(:one) | ||
event.end_date = DateTime.now-2.days | ||
event.save(validate: false) | ||
|
||
ApplicationController.helpers.cleanup | ||
|
||
assert_nil Event.find_by(id: event.id) | ||
end | ||
|
||
test "should remove outdated entries" do | ||
entry = entries(:rwt1) | ||
entry.date = DateTime.now-4.hours | ||
entry.save(validate: false) | ||
|
||
ApplicationController.helpers.cleanup | ||
|
||
assert_nil Entry.find_by(id: entry.id) | ||
end | ||
|
||
test "should remove unconfirmed events" do | ||
event = events(:one) | ||
event.created_at = DateTime.now-1.days | ||
event.confirmed_at = nil | ||
event.save | ||
|
||
ApplicationController.helpers.cleanup | ||
|
||
assert_nil Event.find_by(id: event.id) | ||
end | ||
|
||
test "should remove unconfirmed entries" do | ||
entry = entries(:rwt1) | ||
entry.created_at = DateTime.now-1.days | ||
entry.confirmed_at = nil | ||
entry.save | ||
|
||
ApplicationController.helpers.cleanup | ||
|
||
assert_nil Entry.find_by(id: entry.id) | ||
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