From b2b133b20856182aca3281fc8c10584e95979a81 Mon Sep 17 00:00:00 2001 From: Stephen Chudleigh Date: Thu, 16 Jan 2025 15:20:13 -0800 Subject: [PATCH 1/2] [1508] exclude draft submissions from challenge manager views --- app/models/phase.rb | 3 ++- spec/factories/submission.rb | 2 +- spec/requests/submissions_spec.rb | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/phase.rb b/app/models/phase.rb index e476c70f..9b080fd7 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -22,7 +22,8 @@ class Phase < ApplicationRecord belongs_to :challenge # More relations from phoenix app - has_many :submissions, dependent: :destroy + has_many :all_submissions, class_name: "Submission", dependent: :destroy + has_many :submissions, -> { where(status: "submitted") } has_many :evaluator_submission_assignments, through: :submissions has_one :evaluation_form, dependent: :destroy # has_one :winner, class_name: 'PhaseWinner' diff --git a/spec/factories/submission.rb b/spec/factories/submission.rb index 803994bf..a1a9f795 100644 --- a/spec/factories/submission.rb +++ b/spec/factories/submission.rb @@ -6,7 +6,7 @@ association :submitter, factory: :user title { Faker::Lorem.sentence } - status { "draft" } + status { "submitted" } external_url { "www.example.com" } end end diff --git a/spec/requests/submissions_spec.rb b/spec/requests/submissions_spec.rb index e3904d1d..c84c88e9 100644 --- a/spec/requests/submissions_spec.rb +++ b/spec/requests/submissions_spec.rb @@ -185,6 +185,7 @@ it "renders submission statistics" do create(:submission, challenge: challenge, phase: phase) + create(:submission, challenge: challenge, phase: phase, status: "draft") create(:submission, challenge: challenge, phase: phase, judging_status: "selected") get submissions_phase_path(phase) @@ -198,6 +199,7 @@ end context 'when viewing submissions' do + let!(:draft_submission) { create(:submission, challenge: challenge, phase: phase, status: "draft") } let!(:not_started_submission) { create(:submission, challenge: challenge, phase: phase) } let!(:in_progress_submission) do submission = create(:submission, challenge: challenge, phase: phase) @@ -221,13 +223,15 @@ submission end - it 'displays all submissions and their status counts' do + it 'displays all submissions with status: "submitted" and their status counts' do get submissions_phase_path(phase) [not_started_submission, in_progress_submission, completed_submission, eligible_submission, selected_submission].each do |submission| expect(response.body).to have_css("[data-submission-id='#{submission.id}']") end + # except the drafts + expect(response.body).not_to have_css("[data-submission-id='#{draft_submission.id}']") expect(response.body).to have_css('.text-secondary-dark.text-bold', text: '2') # not_started, eligible expect(response.body).to have_css('.text-accent-warm-dark.text-bold', text: '1') # in_progress From a9673ee39fec33bd501b8c7fe82f0bab658dd05f Mon Sep 17 00:00:00 2001 From: Stephen Chudleigh Date: Thu, 16 Jan 2025 15:44:38 -0800 Subject: [PATCH 2/2] codeclimate --- app/models/phase.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/phase.rb b/app/models/phase.rb index 9b080fd7..d96b50ef 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -23,7 +23,7 @@ class Phase < ApplicationRecord belongs_to :challenge # More relations from phoenix app has_many :all_submissions, class_name: "Submission", dependent: :destroy - has_many :submissions, -> { where(status: "submitted") } + has_many :submissions, -> { where(status: "submitted") }, inverse_of: :phase, dependent: :destroy has_many :evaluator_submission_assignments, through: :submissions has_one :evaluation_form, dependent: :destroy # has_one :winner, class_name: 'PhaseWinner'