-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out CbvApplicant specs per agency
Also simplify the validation logic by using Rails built-ins.
- Loading branch information
Showing
5 changed files
with
132 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe CbvApplicant::Ma, type: :model do | ||
let(:ma_attributes) { attributes_for(:cbv_applicant, :ma) } | ||
|
||
context "user input is invalid" do | ||
it "requires agency_id_number" do | ||
applicant = CbvApplicant.new(ma_attributes.without(:agency_id_number)) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:agency_id_number]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/ma.attributes.agency_id_number.invalid_format'), | ||
) | ||
end | ||
|
||
it "requires beacon_id" do | ||
applicant = CbvApplicant.new(ma_attributes.without(:beacon_id)) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:beacon_id]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/ma.attributes.beacon_id.invalid_format') | ||
) | ||
end | ||
|
||
it "requires beacon_id to have 6 alphanumeric characters" do | ||
applicant = CbvApplicant.new(ma_attributes.merge(beacon_id: '12345')) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:beacon_id]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/ma.attributes.beacon_id.invalid_format') | ||
) | ||
end | ||
|
||
it "validates agency_id_number format" do | ||
applicant = CbvApplicant.new(ma_attributes.merge(agency_id_number: 'invalid')) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:agency_id_number]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/ma.attributes.agency_id_number.invalid_format') | ||
) | ||
end | ||
|
||
it "does not require client_id_number" do | ||
applicant = CbvApplicant.new(ma_attributes.merge(client_id_number: nil)) | ||
expect(applicant).to be_valid | ||
expect(applicant.errors[:client_id_number]).to be_empty | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe CbvApplicant::Nyc, type: :model do | ||
let(:nyc_attributes) { attributes_for(:cbv_applicant, :nyc) } | ||
|
||
context "user input is valid" do | ||
it "formats a 9-character case number with leading zeros" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(case_number: '12345678A')) | ||
expect(applicant).to be_valid | ||
expect(applicant.case_number).to eq('00012345678A') | ||
end | ||
|
||
it "converts case number to uppercase" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(case_number: '12345678a')) | ||
expect(applicant).to be_valid | ||
expect(applicant.case_number).to eq('00012345678A') | ||
end | ||
|
||
it "validates snap_application_date is not older than 30 days" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(snap_application_date: 31.days.ago)) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:snap_application_date]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/nyc.attributes.snap_application_date.nyc_invalid_date') | ||
) | ||
end | ||
end | ||
|
||
context "user input is invalid" do | ||
it "requires case_number" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(case_number: nil)) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:case_number]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/nyc.attributes.case_number.invalid_format'), | ||
) | ||
end | ||
|
||
it "validates invalid case_number format" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(case_number: 'invalid')) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:case_number]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/nyc.attributes.case_number.invalid_format') | ||
) | ||
end | ||
|
||
it "checks that a shorter case number is invalid" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(case_number: '123A')) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:case_number]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/nyc.attributes.case_number.invalid_format') | ||
) | ||
end | ||
|
||
it "validates an invalid 11 char string" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(case_number: '1234567890A')) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.case_number).to eq('1234567890A') | ||
end | ||
|
||
it "validates client_id_number format when present" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(client_id_number: 'invalid')) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:client_id_number]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/nyc.attributes.client_id_number.invalid_format') | ||
) | ||
end | ||
|
||
it "requires valid snap_application_date" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(snap_application_date: "invalid")) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:snap_application_date]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/nyc.attributes.snap_application_date.nyc_invalid_date') | ||
) | ||
end | ||
|
||
it "requires client_id_number" do | ||
applicant = CbvApplicant.new(nyc_attributes.merge(client_id_number: nil)) | ||
expect(applicant).not_to be_valid | ||
expect(applicant.errors[:client_id_number]).to include( | ||
I18n.t('activerecord.errors.models.cbv_applicant/nyc.attributes.client_id_number.invalid_format') | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters