Browse Source

Merge pull request #64 from communitiesuk/CLDC-469-if-served-did-leave-validation

added armed forces active response validation
pull/69/head
Milo 3 years ago committed by GitHub
parent
commit
a78a9a0e13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Gemfile
  2. 10
      app/models/case_log.rb
  3. 8
      docs/api/DLUHC-CORE-Data.v1.json
  4. 6
      spec/helpers/check_answers_helper_spec.rb
  5. 26
      spec/models/case_log_spec.rb
  6. 3
      spec/rails_helper.rb

2
Gemfile

@ -49,10 +49,10 @@ end
group :test do group :test do
gem "capybara", require: false gem "capybara", require: false
gem "database_cleaner-active_record", require: false
gem "factory_bot_rails" gem "factory_bot_rails"
gem "selenium-webdriver", require: false gem "selenium-webdriver", require: false
gem "simplecov", require: false gem "simplecov", require: false
gem "database_cleaner-active_record", require: false
%w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib| %w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: "main", require: false gem lib, git: "https://github.com/rspec/#{lib}.git", branch: "main", require: false
end end

10
app/models/case_log.rb

@ -77,6 +77,16 @@ class CaseLogValidator < ActiveModel::Validator
end end
end end
def validate_armed_forces_active_response(record)
if record.armed_forces == "Yes - a regular" && record.armed_forces_active.blank?
record.errors.add :armed_forces_active, "You must answer the armed forces active question if the tenant has served as a regular in the armed forces"
end
if record.armed_forces != "Yes - a regular" && record.armed_forces_active.present?
record.errors.add :armed_forces_active, "You must not answer the armed forces active question if the tenant has not served as a regular in the armed forces"
end
end
def validate_household_pregnancy(record) def validate_household_pregnancy(record)
if (record.pregnancy == "Yes" || record.pregnancy == "Prefer not to say") && !women_of_child_bearing_age_in_household(record) if (record.pregnancy == "Yes" || record.pregnancy == "Prefer not to say") && !women_of_child_bearing_age_in_household(record)
record.errors.add :pregnancy, "You must answer no as there are no female tenants aged 16-50 in the property" record.errors.add :pregnancy, "You must answer no as there are no female tenants aged 16-50 in the property"

8
docs/api/DLUHC-CORE-Data.v1.json

@ -109,7 +109,7 @@
"Invalid Age": { "Invalid Age": {
"value": { "value": {
"errors": { "errors": {
"tenant_age": [ "person_1_age": [
"Tenant age must be between 0 and 120" "Tenant age must be between 0 and 120"
] ]
} }
@ -219,7 +219,7 @@
"reasonable_preference_reason": [ "reasonable_preference_reason": [
"If reasonable preference is Yes, a reason must be given" "If reasonable preference is Yes, a reason must be given"
], ],
"tenant_age": [ "person_1_age": [
"Tenant age must be between 0 and 120" "Tenant age must be between 0 and 120"
] ]
} }
@ -268,8 +268,8 @@
"x-examples": { "x-examples": {
"example-1": { "example-1": {
"tenant_code": "T657", "tenant_code": "T657",
"tenant_age": 35, "person_1_age": 35,
"tenant_gender": "Female", "person_1_gender": "Female",
"tenant_ethnic_group": "White: English/Scottish/Welsh/Northern Irish/British", "tenant_ethnic_group": "White: English/Scottish/Welsh/Northern Irish/British",
"tenant_nationality": "UK national resident in UK", "tenant_nationality": "UK national resident in UK",
"previous_housing_situation": "Private sector tenancy", "previous_housing_situation": "Private sector tenancy",

6
spec/helpers/check_answers_helper_spec.rb

@ -11,7 +11,9 @@ RSpec.describe CheckAnswersHelper do
) )
end end
let(:case_log_with_met_radio_condition) do let(:case_log_with_met_radio_condition) do
FactoryBot.create(:case_log, armed_forces: "Yes - a regular", armed_forces_injured: "No") FactoryBot.create(:case_log, armed_forces: "Yes - a regular",
armed_forces_injured: "No",
armed_forces_active: "Yes")
end end
let(:subsection) { "income_and_benefits" } let(:subsection) { "income_and_benefits" }
let(:subsection_with_numeric_conditionals) { "household_characteristics" } let(:subsection_with_numeric_conditionals) { "household_characteristics" }
@ -56,7 +58,7 @@ RSpec.describe CheckAnswersHelper do
subsection_with_radio_conditionals, subsection_with_radio_conditionals,
case_log_with_met_radio_condition, case_log_with_met_radio_condition,
form, form,
)).to equal(3) )).to equal(4)
end end
end end

26
spec/models/case_log_spec.rb

@ -132,6 +132,7 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
end end
end end
context "fixed term tenancy length" do context "fixed term tenancy length" do
it "Must not be completed if Type of main tenancy is not responded with either Secure or Assured shorthold " do it "Must not be completed if Type of main tenancy is not responded with either Secure or Assured shorthold " do
expect { expect {
@ -179,6 +180,31 @@ RSpec.describe Form, type: :model do
}.not_to raise_error }.not_to raise_error
end end
end end
context "armed forces active validation" do
it "must be answered if ever served in the forces as a regular" do
expect {
CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_active: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must not be answered if not ever served as a regular" do
expect {
CaseLog.create!(armed_forces: "No",
armed_forces_active: "Yes")
}.to raise_error(ActiveRecord::RecordInvalid)
end
# Crossover over tests here as injured must be answered as well for no error
it "must be answered if ever served in the forces as a regular" do
expect {
CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_active: "Yes",
armed_forces_injured: "Yes")
}.not_to raise_error
end
end
end end
describe "status" do describe "status" do

3
spec/rails_helper.rb

@ -6,7 +6,7 @@ require File.expand_path("../config/environment", __dir__)
abort("The Rails environment is running in production mode!") if Rails.env.production? abort("The Rails environment is running in production mode!") if Rails.env.production?
require "rspec/rails" require "rspec/rails"
require "capybara/rspec" require "capybara/rspec"
require 'database_cleaner/active_record' require "database_cleaner/active_record"
# Comment to run `js: true specs` with visible browser interaction # Comment to run `js: true specs` with visible browser interaction
Capybara.javascript_driver = :selenium_headless Capybara.javascript_driver = :selenium_headless
@ -58,6 +58,7 @@ RSpec.configure do |config|
uncommitted transaction data setup over the spec's database connection. uncommitted transaction data setup over the spec's database connection.
MSG MSG
end end
DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.clean_with(:truncation)
end end

Loading…
Cancel
Save