Skip to content

Commit

Permalink
285 | Adjust query to only show evaluator the phases they have assign…
Browse files Browse the repository at this point in the history
…ed/recused submissions
  • Loading branch information
emmabjj committed Jan 15, 2025
1 parent cec98cd commit af9ce6c
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 51 deletions.
4 changes: 2 additions & 2 deletions app/controllers/evaluations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class EvaluationsController < ApplicationController
before_action :set_phase, only: [:submissions]

def index
@challenges = Challenge.joins(phases: { submissions: :evaluator_submission_assignments }).
@phases = Phase.joins(:evaluator_submission_assignments).
where(evaluator_submission_assignments: {
user_id: current_user.id,
status: [:assigned, :recused]
}).
includes(phases: [:evaluation_form]).
includes(:challenge, :evaluation_form).
distinct
end

Expand Down
58 changes: 28 additions & 30 deletions app/views/evaluations/_phases_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@
</tr>
</thead>
<tbody>
<% @challenges.each do |challenge| %>
<% challenge.phases.each do |phase| %>
<tr>
<th data-label="Challenge Title" scope="row" class="text-top">
<%= challenge_phase_title(challenge, phase) %>
</th>
<td data-label="Assigned to me" class="text-top">
<%= assigned_submissions_count(current_user, challenge, phase) %>
</td>
<td data-label="Remaining to evaluate" class="text-top">
<%= remaining_evaluations_count(current_user, challenge, phase) %>
</td>
<td data-label="Due by" class="text-top">
<% if phase.evaluation_form %>
<%= phase.evaluation_form.closing_date %>
<% else %>
N/A
<% @phases.each do |phase| %>
<tr>
<th data-label="Challenge Title" scope="row" class="text-top">
<%= challenge_phase_title(phase.challenge, phase) %>
</th>
<td data-label="Assigned to me" class="text-top">
<%= assigned_submissions_count(current_user, phase.challenge, phase) %>
</td>
<td data-label="Remaining to evaluate" class="text-top">
<%= remaining_evaluations_count(current_user, phase.challenge, phase) %>
</td>
<td data-label="Due by" class="text-top">
<% if phase.evaluation_form %>
<%= phase.evaluation_form.closing_date %>
<% else %>
N/A
<% end %>
</td>
<td>
<div class="display-flex flex-column grid-row grid-gap-1 padding-bottom-2">
<%= link_to submissions_evaluation_path(phase), class: "usa-button font-body-2xs text-no-wrap width-full" do %>
View Submissions
<% end %>
</td>
<td>
<div class="display-flex flex-column grid-row grid-gap-1 padding-bottom-2">
<%= link_to submissions_evaluation_path(phase), class: "usa-button font-body-2xs text-no-wrap width-full" do %>
View Submissions
<% end %>
</div>
</div>
</td>
</td>
</tr>
<% end %>
<% end %>
</div>
</div>
</td>
</td>
</tr>
<% end %>
</tbody>
</table>
2 changes: 1 addition & 1 deletion app/views/evaluations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Evaluations</h1>
<p class="text-normal padding-bottom-2">View challenges with submissions assigned to me to evaluate.</p>

<% if @challenges.empty? %>
<% if @phases.empty? %>
<div class="text-normal">
<p>You currently do not have any challenges.</p>
</div>
Expand Down
77 changes: 59 additions & 18 deletions spec/requests/evaluations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,55 +66,96 @@
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(:challenge_with_submissions) { create(:challenge, title: "Challenge with Submissions", is_multi_phase: false) }
let(:phase_with_submissions) { challenge_with_submissions.phases.first }

let(:other_challenge) { create(:challenge, title: "Challenge without Assignments", is_multi_phase: false) }
let(:other_phase) { other_challenge.phases.first }
let(:multi_phase_challenge) { create(:challenge, title: "Multi-Phase Challenge", is_multi_phase: true) }
let(:phase1) { create(:phase, challenge: multi_phase_challenge) }
let(:phase2) { create(:phase, challenge: multi_phase_challenge) }

let(:challenge_without_submissions) { create(:challenge, title: "Challenge without Submissions", is_multi_phase: false) }
let(:phase_without_submissions) { challenge_without_submissions.phases.first }

before do
ChallengePhasesEvaluator.create!(challenge: challenge, phase: phase, user: evaluator)
ChallengePhasesEvaluator.create!(challenge: other_challenge, phase: other_phase, user: evaluator)
ChallengePhasesEvaluator.create!(challenge: challenge_with_submissions, phase: phase_with_submissions, user: evaluator)
ChallengePhasesEvaluator.create!(challenge: multi_phase_challenge, phase: phase1, user: evaluator)
ChallengePhasesEvaluator.create!(challenge: challenge_without_submissions, phase: phase_without_submissions, user: evaluator)
end

it "only shows challenges with assigned or recused submissions" do
assigned_submission = create(:submission, phase: phase, challenge: challenge)
it "only shows phases with assigned or recused submissions" do
# Submissions for single phase challenge
assigned_submission = create(:submission, phase: phase_with_submissions, challenge: challenge_with_submissions)
create(:evaluator_submission_assignment,
submission: assigned_submission,
evaluator: evaluator,
status: :assigned
)

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

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

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

# Submissions for multi-phase challenge
multi_phase_submission = create(:submission, phase: phase1, challenge: multi_phase_challenge)
create(:evaluator_submission_assignment,
submission: multi_phase_submission,
evaluator: evaluator,
status: :assigned
)

multi_phase_recused_submission = create(:submission, phase: phase1, challenge: multi_phase_challenge)
create(:evaluator_submission_assignment,
submission: multi_phase_recused_submission,
evaluator: evaluator,
status: :recused
)

multi_phase_unassigned_submission = create(:submission, phase: phase1, challenge: multi_phase_challenge)
create(:evaluator_submission_assignment,
submission: multi_phase_unassigned_submission,
evaluator: evaluator,
status: :unassigned
)

multi_phase_recused_unassigned_submission = create(:submission, phase: phase1, challenge: multi_phase_challenge)
create(:evaluator_submission_assignment,
submission: multi_phase_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')
expect(response.body).to include(challenge_with_submissions.title)
expect(response.body).not_to include(challenge_without_submissions.title)

expect(response.body.scan(/data-label="Challenge Title"/).count).to eq(2)
expect(response.body.scan(/#{multi_phase_challenge.title}/).count).to eq(1)

within("#phase_#{phase_with_submissions.id}") do
expect(page).to have_css('td[data-label="Assigned to me"]', text: '2')
end

within("#phase_#{phase1.id}") do
expect(page).to have_css('td[data-label="Assigned to me"]', text: '2')
end
end
end
end
Expand Down

0 comments on commit af9ce6c

Please sign in to comment.