Browse Source

feat: validate reasonable preference/homeless in bu 23

pull/1687/head
natdeanlewissoftwire 3 years ago
parent
commit
c4b18e9871
  1. 4
      app/controllers/form_controller.rb
  2. 4
      app/models/form/question.rb
  3. 2
      app/models/log.rb
  4. 9
      app/services/bulk_upload/lettings/year2023/row_parser.rb

4
app/controllers/form_controller.rb

@ -95,7 +95,7 @@ private
next unless question_params
if %w[checkbox validation_override].include?(question.type)
question.answer_options.keys.reject { |x| x.match(/divider/) }.each do |option|
question.answer_options.answer_keys_without_dividers.each do |option|
result[option] = question_params.include?(option) ? 1 : 0
end
else
@ -194,7 +194,7 @@ private
def question_missing_response?(responses_for_page, question)
if %w[checkbox validation_override].include?(question.type)
answered = question.answer_options.keys.reject { |x| x.match(/divider/) }.map do |option|
answered = question.answer_keys_without_dividers.map do |option|
session["fields"][option] = @log[option] = params[@log.model_name.param_key][question.id].include?(option) ? 1 : 0
params[@log.model_name.param_key][question.id].exclude?(option)
end

4
app/models/form/question.rb

@ -247,6 +247,10 @@ class Form::Question
end
end
def answer_keys_without_dividers
answer_options.keys.reject { |x| x.match(/divider/) }
end
private
def selected_answer_option_is_derived?(log)

2
app/models/log.rb

@ -108,7 +108,7 @@ class Log < ApplicationRecord
question = form.questions.find { |q| q.id == error.attribute.to_s }
if question.type == "checkbox"
question.answer_options.each_key { |attribute| public_send("#{attribute}=", nil) }
question.answer_keys_without_dividers { |attribute| public_send("#{attribute}=", nil) }
else
public_send("#{error.attribute}=", nil)
end

9
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -357,6 +357,7 @@ class BulkUpload::Lettings::Year2023::RowParser
validate :validate_dont_know_disabled_needs_conjunction, on: :after_log
validate :validate_no_and_dont_know_disabled_needs_conjunction, on: :after_log
validate :validate_no_housing_needs_questions_answered, on: :after_log
validate :validate_reasonable_preference_homeless, on: :after_log
validate :validate_if_log_already_exists, on: :after_log, if: -> { FeatureToggle.bulk_upload_duplicate_log_check_enabled? }
validate :validate_owning_org_data_given, on: :after_log
@ -617,6 +618,14 @@ private
end
end
def validate_reasonable_preference_homeless
if field_110 == 1
if field_105 == 1 && field_111 == 1
errors.add(:field_111, I18n.t("validations.household.reasonpref.not_homeless"))
end
end
end
def validate_lettings_type_matches_bulk_upload
if [1, 3, 5, 7, 9, 11].include?(field_5) && !general_needs?
errors.add(:field_5, I18n.t("validations.setup.lettype.supported_housing_mismatch"))

Loading…
Cancel
Save