From 4fefbde0c62775580738ed9407623073878ec4eb Mon Sep 17 00:00:00 2001 From: Alex Kiessling <32677188+ajkiessl@users.noreply.github.com> Date: Mon, 9 Sep 2024 08:53:09 -0400 Subject: [PATCH] 759 federal funding language (#839) * 759 - Omits federal funding validation for graduate Because of how federal funding details is saved, federal funding may not pass validation because of a race condition. This change turns off the validation for graduate submissions. * Only build federal_funding_details for graduate instance * Adds some more tests * Validate federal_funding_details through submission only for graduate * Fix test * I think federal_funding_details was building and saving before it could be reassigned to the factory bot federal_funding_details. I fixed this by just updating the existing federal funding details with valid values * Removes byebug * Rubocop * Only set federal_funding_details for graduate instance * rubocop --------- Co-authored-by: Jesse Landis-Eigsti --- app/models/submission.rb | 5 +- .../author/submit_final_submission_spec.rb | 7 +- spec/models/submission_spec.rb | 91 ++++++++++++++++--- 3 files changed, 87 insertions(+), 16 deletions(-) diff --git a/app/models/submission.rb b/app/models/submission.rb index 40cb05404..01b4484a6 100755 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -79,7 +79,8 @@ def program_head length: { maximum: 400 }, presence: true, if: proc { |s| s.author_edit } - validates :federal_funding, inclusion: { in: [true, false] }, if: proc { |s| s.status_behavior.beyond_collecting_committee? && s.author_edit } + validates :federal_funding, inclusion: { in: [true, false] }, if: proc { |s| s.status_behavior.beyond_collecting_committee? && s.author_edit && !current_partner.graduate? } + validates_associated :federal_funding_details, message: 'Federal funding is invalid.', if: -> { current_partner.graduate? } validates :abstract, :keywords, @@ -383,7 +384,7 @@ def voting_committee_members end def federal_funding_details - super || build_federal_funding_details + super || (build_federal_funding_details if current_partner.graduate?) end # Initialize our committee members with empty records for each of the required roles. diff --git a/spec/integration/author/submit_final_submission_spec.rb b/spec/integration/author/submit_final_submission_spec.rb index febacafc1..3d25354f5 100644 --- a/spec/integration/author/submit_final_submission_spec.rb +++ b/spec/integration/author/submit_final_submission_spec.rb @@ -4,6 +4,12 @@ describe "When collecting final submission files", honors: true, milsch: true do before do oidc_authorize_author + if current_partner.graduate? + submission.federal_funding_details.update(training_support_funding: false, + other_funding: false, + training_support_acknowledged: false, + other_funding_acknowledged: false) + end end let!(:author) { current_author } @@ -11,7 +17,6 @@ let!(:committee_members) { create_committee(submission) } let!(:degree) { FactoryBot.create :degree, degree_type: DegreeType.default } let!(:approval_configuration) { FactoryBot.create :approval_configuration, degree_type: degree.degree_type, head_of_program_is_approving: false } - let!(:federal_funding_details) { FactoryBot.create :federal_funding_details, submission: } context "when I submit the 'Upload Final Submission Files' form" do it 'loads the page' do diff --git a/spec/models/submission_spec.rb b/spec/models/submission_spec.rb index 419b1302d..f6ab907df 100755 --- a/spec/models/submission_spec.rb +++ b/spec/models/submission_spec.rb @@ -266,20 +266,65 @@ expect(submission).to be_valid end - it 'validates federal funding only when authors are editing beyond collecting committee' do - submission = FactoryBot.create :submission, :waiting_for_final_submission_response - submission2 = FactoryBot.create :submission, :collecting_program_information - submission.author_edit = true - submission.federal_funding = true - expect(submission).to be_valid - submission.federal_funding = false - expect(submission).to be_valid - submission.federal_funding = nil + describe 'validating federal funding only when authors are editing beyond collecting committee', honors: true do + context 'when current_partner is not graduate' do + it 'validates depending on certain criteria' do + skip 'non-graduate only' if current_partner.graduate? + + submission = FactoryBot.create :submission, :waiting_for_final_submission_response + submission2 = FactoryBot.create :submission, :collecting_program_information + submission.author_edit = true + submission.federal_funding = true + expect(submission).to be_valid + submission.federal_funding = false + expect(submission).to be_valid + submission.federal_funding = nil + expect(submission).not_to be_valid + submission2.federal_funding = nil + expect(submission2).to be_valid + submission.author_edit = false + submission.federal_funding = nil + expect(submission).to be_valid + end + end + + context 'when current_partner is graduate' do + it "does not validate so it's always valid" do + skip 'graduate only' unless current_partner.graduate? + + submission = FactoryBot.create :submission, :waiting_for_final_submission_response + submission2 = FactoryBot.create :submission, :collecting_program_information + submission.author_edit = true + submission.federal_funding = true + expect(submission).to be_valid + submission.federal_funding = false + expect(submission).to be_valid + submission.federal_funding = nil + expect(submission).to be_valid + submission2.federal_funding = nil + expect(submission2).to be_valid + submission.author_edit = false + submission.federal_funding = nil + expect(submission).to be_valid + end + end + end + + it 'validates federal_funding_details if current_partner graduate' do + skip 'graduate only' unless current_partner.graduate? + + submission = create :submission, :waiting_for_final_submission_response + submission.build_federal_funding_details + submission.federal_funding_details.author_edit = true expect(submission).not_to be_valid - submission2.federal_funding = nil - expect(submission2).to be_valid - submission.author_edit = false - submission.federal_funding = nil + end + + it 'does not validate federal_funding_details if current_partner is not graduate', honors: true do + skip 'non-graduate only' if current_partner.graduate? + + submission = create :submission, :waiting_for_final_submission_response + submission.build_federal_funding_details + submission.federal_funding_details.author_edit = true expect(submission).to be_valid end @@ -1128,4 +1173,24 @@ end end end + + describe '#federal_funding_details' do + context 'when current_partner is graduate' do + it 'builds an empty federal_funding_details record' do + skip 'graduate only' unless current_partner.graduate? + + submission = described_class.new + expect(submission.federal_funding_details.class).to eq FederalFundingDetails + end + end + + context 'when current_partner is not graduate', honors: true do + it "doesn't build a federal_funding_details record" do + skip 'non-graduate only' if current_partner.graduate? + + submission = described_class.new + expect(submission.federal_funding_details.class).to eq NilClass + end + end + end end