From 9601866b47b5695e7b8404d64253b3ed46eb81fd Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Thu, 23 Jan 2025 13:29:45 +0000 Subject: [PATCH] Only award 48in24 badge to participants --- app/models/badges/participant_in_48_in_24_badge.rb | 2 ++ test/models/badges/participant_in_48_in_24_badge_test.rb | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/badges/participant_in_48_in_24_badge.rb b/app/models/badges/participant_in_48_in_24_badge.rb index f007380ffe..0cb48a07fb 100644 --- a/app/models/badges/participant_in_48_in_24_badge.rb +++ b/app/models/badges/participant_in_48_in_24_badge.rb @@ -6,6 +6,8 @@ class ParticipantIn48In24Badge < Badge 'Participated in the #48in24 challenge and achieved a medal' def award_to?(user) + return false unless user.challenges.where(challenge_id: "48in24").exists? + exercises = User::Challenges::FeaturedExercisesProgress48In24.(user) exercises.any? { |e| e.status != :in_progress } end diff --git a/test/models/badges/participant_in_48_in_24_badge_test.rb b/test/models/badges/participant_in_48_in_24_badge_test.rb index b1a253f514..2848a02692 100644 --- a/test/models/badges/participant_in_48_in_24_badge_test.rb +++ b/test/models/badges/participant_in_48_in_24_badge_test.rb @@ -21,9 +21,9 @@ class Badge::ParticipantIn48In24BadgeTest < ActiveSupport::TestCase leap[t] = create(:practice_exercise, track: tracks[t], slug: 'leap') end user = create :user + challenge = create :user_challenge, user:, challenge_id: '48in24' # No solutions - create :user_challenge, user:, challenge_id: '48in24' refute badge.award_to?(user.reload), "new user does not qualify" # One exercise before 2024 does not qualify @@ -51,6 +51,10 @@ class Badge::ParticipantIn48In24BadgeTest < ActiveSupport::TestCase completed_at: Time.utc(2024, SecureRandom.rand(1..12), SecureRandom.rand(1..28))) assert badge.award_to?(user.reload), "one solution in 2024 qualifies" + # Has to have joined the challenge + challenge.destroy + refute badge.award_to?(user.reload), "user has to have joined the challenge" + # One exercise on Dec 31, 2023 user_2 = create :user create :user_challenge, user: user_2, challenge_id: '48in24'