Skip to content

Commit

Permalink
759 federal funding language (#839)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
ajkiessl and jlandiseigsti authored Sep 9, 2024
1 parent 2dbade5 commit 4fefbde
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 16 deletions.
5 changes: 3 additions & 2 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion spec/integration/author/submit_final_submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
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 }
let!(:submission) { FactoryBot.create :submission, :collecting_final_submission_files, lion_path_degree_code: 'PHD', author:, degree: }
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
Expand Down
91 changes: 78 additions & 13 deletions spec/models/submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 4fefbde

Please sign in to comment.