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
gem "capybara", require: false
gem "database_cleaner-active_record", require: false
gem "factory_bot_rails"
gem "selenium-webdriver", 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|
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: "main", require: false
end

10
app/models/case_log.rb

@ -77,6 +77,16 @@ class CaseLogValidator < ActiveModel::Validator
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)
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"

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

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

6
spec/helpers/check_answers_helper_spec.rb

@ -11,7 +11,9 @@ RSpec.describe CheckAnswersHelper do
)
end
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
let(:subsection) { "income_and_benefits" }
let(:subsection_with_numeric_conditionals) { "household_characteristics" }
@ -56,7 +58,7 @@ RSpec.describe CheckAnswersHelper do
subsection_with_radio_conditionals,
case_log_with_met_radio_condition,
form,
)).to equal(3)
)).to equal(4)
end
end

26
spec/models/case_log_spec.rb

@ -132,6 +132,7 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
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
expect {
@ -179,6 +180,31 @@ RSpec.describe Form, type: :model do
}.not_to raise_error
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
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?
require "rspec/rails"
require "capybara/rspec"
require 'database_cleaner/active_record'
require "database_cleaner/active_record"
# Comment to run `js: true specs` with visible browser interaction
Capybara.javascript_driver = :selenium_headless
@ -58,6 +58,7 @@ RSpec.configure do |config|
uncommitted transaction data setup over the spec's database connection.
MSG
end
DatabaseCleaner.clean_with(:truncation)
end

Loading…
Cancel
Save