Skip to content

Commit

Permalink
apply corrections completely
Browse files Browse the repository at this point in the history
  • Loading branch information
glennj committed Dec 19, 2024
1 parent 9b04d6a commit 5cc2e97
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
12 changes: 6 additions & 6 deletions test/models/badges/larisa_latynina_badge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@ class Badge::LarisaLatyninaBadgeTest < ActiveSupport::TestCase
# One bronze all year
exercise = create(:practice_exercise, track: tracks[:csharp], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[:csharp], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
refute badge.award_to?(user.reload), "one bronze does not qualify"

# One silver medal: csharp+tcl+wren are never the featured tracks for an exercise
%i[tcl wren].each do |track_slug|
exercise = create(:practice_exercise, track: tracks[track_slug], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[track_slug], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload), "one silver does not qualify"

# One gold medal
week_1[:featured_tracks].each do |track_slug|
exercise = create(:practice_exercise, track: tracks[track_slug.to_sym], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[track_slug.to_sym], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload), "one gold does not qualify"

# in addition to week 1 gold, add 46 bronze medals: 47 medals does not qualify
exercises.reject { |e| e[:week] == 1 || e[:week] == 48 }.each do |e|
exercise = create(:practice_exercise, track: tracks[:csharp], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[:csharp], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload), "47 medals does not qualify"

Expand All @@ -70,7 +70,7 @@ class Badge::LarisaLatyninaBadgeTest < ActiveSupport::TestCase
%i[tcl wren].each do |t|
exercise = create(:practice_exercise, track: tracks[t], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[t], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
end
assert badge.award_to?(user.reload), "48 golds&silvers qualifies"
Expand All @@ -82,7 +82,7 @@ class Badge::LarisaLatyninaBadgeTest < ActiveSupport::TestCase

exercise = create(:practice_exercise, track: tracks[t], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[t], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
end
assert badge.award_to?(user.reload), "48 golds qualifies"
Expand Down
19 changes: 9 additions & 10 deletions test/models/badges/paavo_nurmi_badge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,50 @@ class Badge::PaavoNurmiBadgeTest < ActiveSupport::TestCase
# One bronze all year
exercise = create(:practice_exercise, track: tracks[:csharp], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[:csharp], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
refute badge.award_to?(user.reload)

# One silver medal: csharp+tcl+wren are never the featured tracks for an exercise
%i[tcl wren].each do |track_slug|
exercise = create(:practice_exercise, track: tracks[track_slug], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[track_slug], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload)

# One gold medal
week_1[:featured_tracks].each do |track_slug|
exercise = create(:practice_exercise, track: tracks[track_slug.to_sym], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[track_slug.to_sym], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload)

# in addition to week 1 gold, add 46 bronze medals: 47 medals does not qualify
exercises.reject { |e| e[:week] == 1 || e[:week] == 48 }.each do |e|
exercise = create(:practice_exercise, track: tracks[:csharp], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[:csharp], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload)

# add week 48 solution, not in 2024
week_48 = exercises.find { |e| e[:week] == 48 }
exercise = create(:practice_exercise, track: tracks[:csharp], slug: week_48[:slug])
solution = create(:practice_solution, :published, user:, track: tracks[:csharp], exercise:,
published_at: Time.utc(2023, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2023, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
refute badge.award_to?(user.reload)

# add an iteration to week 48
iteration = create(:iteration, solution:)
iteration.update(created_at: Time.utc(2024, 1, 1, 0, 0, 0))
# change completion date to 2024, still does not qualify
solution.update(completed_at: Time.utc(2024, 1, 1, 0, 0, 0))
refute badge.award_to?(user.reload)

# 48 gold or silver medals
exercises.reject { |e| e[:week] == 1 }.each do |e|
%i[tcl wren].each do |t|
exercise = create(:practice_exercise, track: tracks[t], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[t], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
end
assert badge.award_to?(user.reload)
Expand All @@ -85,7 +84,7 @@ class Badge::PaavoNurmiBadgeTest < ActiveSupport::TestCase

exercise = create(:practice_exercise, track: tracks[t], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[t], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
end
assert badge.award_to?(user.reload)
Expand Down
19 changes: 9 additions & 10 deletions test/models/badges/usain_bolt_badge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,50 @@ class Badge::UsainBoltBadgeTest < ActiveSupport::TestCase
# One bronze all year
exercise = create(:practice_exercise, track: tracks[:csharp], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[:csharp], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
refute badge.award_to?(user.reload)

# One silver medal: csharp+tcl+wren are never the featured tracks for an exercise
%i[tcl wren].each do |track_slug|
exercise = create(:practice_exercise, track: tracks[track_slug], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[track_slug], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload)

# One gold medal
week_1[:featured_tracks].each do |track_slug|
exercise = create(:practice_exercise, track: tracks[track_slug.to_sym], slug: week_1[:slug])
create(:practice_solution, :published, user:, track: tracks[track_slug.to_sym], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload)

# in addition to week 1 gold, add 46 bronze medals: 47 medals does not qualify
exercises.reject { |e| e[:week] == 1 || e[:week] == 48 }.each do |e|
exercise = create(:practice_exercise, track: tracks[:csharp], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[:csharp], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
refute badge.award_to?(user.reload)

# add week 48 solution, not in 2024
week_48 = exercises.find { |e| e[:week] == 48 }
exercise = create(:practice_exercise, track: tracks[:csharp], slug: week_48[:slug])
solution = create(:practice_solution, :published, user:, track: tracks[:csharp], exercise:,
published_at: Time.utc(2023, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2023, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
refute badge.award_to?(user.reload)

# add an iteration to week 48 to qualify
iteration = create(:iteration, solution:)
iteration.update(created_at: Time.utc(2024, 1, 1, 0, 0, 0))
# change completion date to 2024, still does not qualify
solution.update(completed_at: Time.utc(2024, 1, 1, 0, 0, 0))
refute badge.award_to?(user.reload)

# 48 gold or silver medals
exercises.reject { |e| e[:week] == 1 }.each do |e|
%i[tcl wren].each do |t|
exercise = create(:practice_exercise, track: tracks[t], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[t], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
end
refute badge.award_to?(user.reload)
Expand All @@ -85,7 +84,7 @@ class Badge::UsainBoltBadgeTest < ActiveSupport::TestCase

exercise = create(:practice_exercise, track: tracks[t], slug: e[:slug])
create(:practice_solution, :published, user:, track: tracks[t], exercise:,
published_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28)))
end
end
assert badge.award_to?(user.reload)
Expand Down

0 comments on commit 5cc2e97

Please sign in to comment.