Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only award 48in24 badge to participants #7373

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/badges/participant_in_48_in_24_badge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/models/badges/participant_in_48_in_24_badge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
Loading