Skip to content

Commit

Permalink
Add validation for grade on other qualifications if the jobseeker has…
Browse files Browse the repository at this point in the history
… finished studying
  • Loading branch information
KyleMacPherson committed Jan 22, 2025
1 parent 5287239 commit dfa65b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/form_models/jobseekers/qualifications/other_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class Jobseekers::Qualifications::OtherForm < Jobseekers::Qualifications::Qualif
attr_accessor :subject, :grade

validates :finished_studying, :institution, :name, presence: true
validates :grade, presence: true, if: -> { finished_studying == "true" }
end
10 changes: 9 additions & 1 deletion spec/form_models/jobseekers/qualifications/other_form_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Jobseekers::Qualifications::OtherForm, type: :model do
subject { described_class.new(params) }
subject(:form) { described_class.new(params) }
let(:params) { {} }

it { is_expected.to validate_presence_of(:category) }
Expand All @@ -13,11 +13,19 @@
let(:params) { { "finished_studying" => "false" } }

it { is_expected.to validate_presence_of(:finished_studying_details) }
it { is_expected.not_to validate_presence_of(:grade) }
end

context "when finished studying is true" do
let(:params) { { "finished_studying" => "true" } }

it { is_expected.to validate_numericality_of(:year).is_less_than_or_equal_to(Time.current.year) }
it { is_expected.to validate_presence_of(:grade) }

it "raises error without a grade" do
form.grade = nil
expect(form).not_to be_valid
expect(form.errors[:grade]).to include("Enter a grade")
end
end
end

0 comments on commit dfa65b4

Please sign in to comment.