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

[285] Adjust Challenge Phase index query for Evaluators #359

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 6 additions & 3 deletions app/controllers/evaluations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ class EvaluationsController < ApplicationController
before_action :set_phase, only: [:submissions]

def index
@challenges = Challenge.joins(phases: :challenge_phases_evaluators).
where(challenge_phases_evaluators: { user_id: current_user.id }).
@challenges = Challenge.joins(phases: { submissions: :evaluator_submission_assignments }).
where(evaluator_submission_assignments: {
user_id: current_user.id,
status: [:assigned, :recused]
}).
includes(phases: [:evaluation_form]).
distinct
end
Expand Down Expand Up @@ -171,4 +174,4 @@ def evaluation_params
end
end
# TODO: Remove this after above refactor
# rubocop:enable all
# rubocop:enable all
55 changes: 55 additions & 0 deletions spec/requests/evaluations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,61 @@
expect(response).to redirect_to(ENV.fetch("PHOENIX_URI", nil))
end
end

context "when logged in as an evaluator" do
let(:evaluator) { create_and_log_in_user(role: 'evaluator') }

let(:challenge) { create(:challenge, title: "Challenge with Assignments", is_multi_phase: false) }
let(:phase) { challenge.phases.first }

let(:other_challenge) { create(:challenge, title: "Challenge without Assignments", is_multi_phase: false) }
let(:other_phase) { other_challenge.phases.first }

before do
ChallengePhasesEvaluator.create!(challenge: challenge, phase: phase, user: evaluator)
ChallengePhasesEvaluator.create!(challenge: other_challenge, phase: other_phase, user: evaluator)
end

it "only shows challenges with assigned or recused submissions" do
assigned_submission = create(:submission, phase: phase, challenge: challenge)
create(:evaluator_submission_assignment,
submission: assigned_submission,
evaluator: evaluator,
status: :assigned
)

recused_submission = create(:submission, phase: phase, challenge: challenge)
create(:evaluator_submission_assignment,
submission: recused_submission,
evaluator: evaluator,
status: :recused
)

unassigned_submission = create(:submission, phase: phase, challenge: challenge)
create(:evaluator_submission_assignment,
submission: unassigned_submission,
evaluator: evaluator,
status: :unassigned
)

recused_unassigned_submission = create(:submission, phase: phase, challenge: challenge)
create(:evaluator_submission_assignment,
submission: recused_unassigned_submission,
evaluator: evaluator,
status: :recused_unassigned
)

get evaluations_path

expect(response.body).to include(challenge.title)
expect(response.body).not_to include(other_challenge.title)
expect(response.body.scan(/data-label="Challenge Title"/).count).to eq(1)
expect(response.body).to have_css('td[data-label="Assigned to me"]')
expect(response.body).to have_css('td[data-label="Assigned to me"]', text: '2')
expect(response.body).to have_css('td[data-label="Remaining to evaluate"]')
expect(response.body).to have_css('td[data-label="Remaining to evaluate"]', text: '2')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these are duplicated expectations and can be collapsed to one line

Suggested change
expect(response.body).to have_css('td[data-label="Assigned to me"]')
expect(response.body).to have_css('td[data-label="Assigned to me"]', text: '2')
expect(response.body).to have_css('td[data-label="Remaining to evaluate"]')
expect(response.body).to have_css('td[data-label="Remaining to evaluate"]', text: '2')
expect(response.body).to have_css('td[data-label="Assigned to me"]', text: '2')
expect(response.body).to have_css('td[data-label="Remaining to evaluate"]', text: '2')

end
end
end

describe "GET /evaluations/:id/submissions" do
Expand Down
Loading