Skip to content

Commit

Permalink
Add maximum reputation for representation (#6160)
Browse files Browse the repository at this point in the history
* Add maximum reputation for representation

* Fix failing test
  • Loading branch information
ErikSchierboom authored Sep 20, 2023
1 parent 583d598 commit 68ff9d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def call
num_loc: solution.num_loc,
num_solutions: representation.num_published_solutions,
code: published_iteration.submission.files.map(&:content) || [],
max_reputation:,
exercise: {
id: solution.exercise.id,
slug: solution.exercise.slug,
Expand All @@ -50,5 +51,15 @@ def passes_latest_tests?
exists?
end

def max_reputation
User::ReputationPeriod.where(
period: :forever,
category: :any,
about: :track,
track_id: representation.track_id,
user_id: representation.published_solutions.select(:user_id)
).maximum(:reputation).to_i
end

attr_reader :solution, :published_iteration
end
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Exercise::Representation::CreateSearchIndexDocumentTest < ActiveSupport::T
featured_solution_id: solution.id,
num_loc: solution.num_loc,
num_solutions: num_published_solutions,
max_reputation: 0,
code: [content],
exercise: {
id: solution.exercise.id,
Expand All @@ -75,6 +76,30 @@ class Exercise::Representation::CreateSearchIndexDocumentTest < ActiveSupport::T
assert_equal expected, Exercise::Representation::CreateSearchIndexDocument.(representation)
end

test "chooses highest reputation" do
representation = create(:exercise_representation)

users = create_list(:user, 3) do |user|
solution = create :practice_solution, :published, user:,
published_exercise_representation: representation,
published_iteration_head_tests_status: :passed
submission = create(:submission, solution:)
create(:submission_file, submission:, content: "foo")
create(:iteration, submission:)
end

assert_equal 0, Exercise::Representation::CreateSearchIndexDocument.(representation)[:max_reputation]

create :user_reputation_period, user: users[0], reputation: 20,
period: :forever, category: :any, about: :track, track_id: representation.track_id
create :user_reputation_period, user: users[1], reputation: 50,
period: :forever, category: :any, about: :track, track_id: representation.track_id
create :user_reputation_period, user: users[2], reputation: 13,
period: :forever, category: :any, about: :track, track_id: representation.track_id

assert_equal 50, Exercise::Representation::CreateSearchIndexDocument.(representation)[:max_reputation]
end

test "chooses correct solution" do
representation = create(:exercise_representation)

Expand Down

0 comments on commit 68ff9d3

Please sign in to comment.