Skip to content

Commit

Permalink
Add presence valdiation for enic_reason
Browse files Browse the repository at this point in the history
  • Loading branch information
gms-gs committed Jul 31, 2024
1 parent 6ca18cd commit 3f76149
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/application_qualification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ApplicationQualification < ApplicationRecord

validates :qualification_type, length: { maximum: MAX_QUALIFICATION_TYPE_LENGTH }, allow_blank: true
validates :non_uk_qualification_type, length: { maximum: MAX_QUALIFICATION_TYPE_LENGTH }, allow_blank: true
validates :enic_reason, presence: true, on: :create

enum enic_reason: {
obtained: 'obtained',
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/application_qualification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
institution_country { international? ? Faker::Address.country_code : 'GB' }
equivalency_details { Faker::Lorem.paragraph_by_chars(number: 200) }

trait :skip_validate do
to_create { |instance| instance.save(validate: false) }
end

factory :gcse_qualification do
level { 'gcse' }
qualification_type { 'gcse' }
Expand Down
9 changes: 9 additions & 0 deletions spec/forms/candidate_interface/maths_gcse_grade_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@

expect(gcse.reload.grade).to eq('D')
end

it 'does not raise validation error for enic_reason being nil' do
gcse = create(:gcse_qualification, :skip_validate, enic_reason: nil, enic_reference: nil)
form = described_class.new(grade: 'other', other_grade: 'D', qualification_type: 'non_uk')

form.save(gcse)

expect(gcse.reload.enic_reason).to be_nil
end
end

describe '.build_from_qualification' do
Expand Down

0 comments on commit 3f76149

Please sign in to comment.