mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-01 20:25:26 +00:00
Added a daily recurring job to cleanup tournaments .
This commit is contained in:
11
test/fixtures/tournaments.yml
vendored
11
test/fixtures/tournaments.yml
vendored
@@ -9,4 +9,15 @@ one:
|
||||
tournament_type: Pool to bracket
|
||||
user_id: 1
|
||||
date: 2015-12-30
|
||||
is_public: true
|
||||
|
||||
two:
|
||||
id: 2
|
||||
name: Test Tournament 2
|
||||
address: Some Place
|
||||
director: Jacob Cody Wimer
|
||||
director_email: jacob.wimer@gmail.com
|
||||
tournament_type: Pool to bracket
|
||||
user_id: 1
|
||||
date: 2015-12-30
|
||||
is_public: true
|
||||
49
test/jobs/tournament_cleanup_job_test.rb
Normal file
49
test/jobs/tournament_cleanup_job_test.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TournamentCleanupJobTest < ActiveJob::TestCase
|
||||
setup do
|
||||
# Create an old empty tournament (1 week old, 0 finished matches)
|
||||
@old_empty_tournament = tournaments(:one)
|
||||
@old_empty_tournament.update(date: 2.weeks.ago.to_date)
|
||||
|
||||
# Create an old active tournament (1 week old, with finished matches)
|
||||
@old_active_tournament = tournaments(:two)
|
||||
@old_active_tournament.update(date: 2.weeks.ago.to_date)
|
||||
|
||||
# Add a finished match to the active tournament
|
||||
match = matches(:one)
|
||||
match.update(tournament_id: @old_active_tournament.id, finished: 1, winner_id: wrestlers(:one).id)
|
||||
|
||||
# Add delegates to test removal
|
||||
tournament_delegate = TournamentDelegate.create(tournament: @old_active_tournament, user: users(:one))
|
||||
school = schools(:one)
|
||||
school.update(tournament_id: @old_active_tournament.id)
|
||||
school_delegate = SchoolDelegate.create(school: school, user: users(:one))
|
||||
end
|
||||
|
||||
test "removes old empty tournaments" do
|
||||
assert_difference 'Tournament.count', -1 do
|
||||
TournamentCleanupJob.perform_now
|
||||
end
|
||||
|
||||
assert_raises(ActiveRecord::RecordNotFound) { @old_empty_tournament.reload }
|
||||
end
|
||||
|
||||
test "cleans up old active tournaments" do
|
||||
TournamentCleanupJob.perform_now
|
||||
|
||||
# Tournament should still exist
|
||||
@old_active_tournament.reload
|
||||
|
||||
# User association should be removed
|
||||
assert_nil @old_active_tournament.user_id
|
||||
|
||||
# Tournament delegates should be removed
|
||||
assert_equal 0, @old_active_tournament.delegates.count
|
||||
|
||||
# School delegates should be removed
|
||||
@old_active_tournament.schools.each do |school|
|
||||
assert_equal 0, school.delegates.count
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user