diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 6b8bdd00d..c6cad74a3 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -134,10 +134,8 @@ private questions_for_page.each do |question, content| if content.key?("conditional_route_to") content["conditional_route_to"].each do |route, answer| - if !responses_for_page[question].nil? - if answer.include?(responses_for_page[question]) - return "case_log_#{route}_path" - end + if responses_for_page[question].present? && answer.include?(responses_for_page[question]) + return "case_log_#{route}_path" end end end diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 5edbfb69b..5224850f3 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -13,36 +13,36 @@ module CheckAnswersHelper total_questions = {} page_name = form.pages_for_subsection(subsection).keys.first - while page_name != "check_answers" && page_name != :check_answers + while page_name.to_s != "check_answers" questions = form.questions_for_page(page_name) question_key = questions.keys[0] question_value = questions.values[0] - appliccable_questions = filter_conditional_questions(questions, case_log) - total_questions = total_questions.merge(appliccable_questions) + applicable_questions = filter_conditional_questions(questions, case_log) + total_questions = total_questions.merge(applicable_questions) - page_name = get_next_page_name(form, page_name, appliccable_questions, question_key, case_log, question_value) + page_name = get_next_page_name(form, page_name, applicable_questions, question_key, case_log, question_value) end total_questions end def filter_conditional_questions(questions, case_log) - appliccable_questions = questions + applicable_questions = questions questions.each do |k, question| question.fetch("conditional_for", []).each do |conditional_question_key, condition| if condition_not_met(case_log, k, question, condition) - appliccable_questions = appliccable_questions.reject { |z| z == conditional_question_key } + applicable_questions = applicable_questions.reject { |z| z == conditional_question_key } end end end - appliccable_questions + applicable_questions end - def get_next_page_name(form, page_name, appliccable_questions, question_key, case_log, question_value) - if appliccable_questions[question_key].key?("conditional_route_to") - appliccable_questions[question_key]["conditional_route_to"].each do |conditional_page_key, condition| + def get_next_page_name(form, page_name, applicable_questions, question_key, case_log, question_value) + if applicable_questions[question_key].key?("conditional_route_to") + applicable_questions[question_key]["conditional_route_to"].each do |conditional_page_key, condition| unless condition_not_met(case_log, question_key, question_value, condition) return conditional_page_key end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index fd63535d5..775b1c609 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -28,7 +28,7 @@ class CaseLogValidator < ActiveModel::Validator end end end - + def validate_other_reason_for_leaving_last_settled_home(record) if record.reason_for_leaving_last_settled_home == "Other" && record.other_reason_for_leaving_last_settled_home.blank? record.errors.add :other_reason_for_leaving_last_settled_home, "If reason for leaving settled home is other then the other reason must be provided" @@ -44,10 +44,10 @@ class CaseLogValidator < ActiveModel::Validator # that have just been submitted. If we're submitting a log via API or Bulk Upload # we want to validate all data fields. question_to_validate = options[:previous_page] - if question_to_validate + if question_to_validate if respond_to?("validate_#{question_to_validate}") public_send("validate_#{question_to_validate}", record) - end + end else # This assumes that all methods in this class other than this one are # validations to be run diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb index e120a7211..9025cf42d 100644 --- a/app/views/form/_check_answers_table.html.erb +++ b/app/views/form/_check_answers_table.html.erb @@ -1,7 +1,7 @@
- <%= question_info["check_answer_label"].to_s != "" ? question_info["check_answer_label"].to_s : question_info["header"].to_s%> + <%= question_info["check_answer_label"].to_s.present? ? question_info["check_answer_label"].to_s : question_info["header"].to_s%>
<%= @case_log[question_title] %> diff --git a/db/schema.rb b/db/schema.rb index 03a612ecd..20dbfc383 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -84,6 +84,7 @@ ActiveRecord::Schema.define(version: 2021_10_15_090040) do t.string "property_void_date" t.string "property_major_repairs" t.string "property_major_repairs_date" + t.integer "property_number_of_times_relet" t.string "property_wheelchair_accessible" t.string "net_income" t.string "net_income_frequency" @@ -131,7 +132,6 @@ ActiveRecord::Schema.define(version: 2021_10_15_090040) do t.boolean "reasonable_preference_reason_avoid_hardship" t.boolean "reasonable_preference_reason_do_not_know" t.datetime "discarded_at" - t.integer "property_number_of_times_relet" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 6b1124241..d3e4d74a9 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -28,32 +28,31 @@ RSpec.describe Form, type: :model do describe "reasonable preference validation" do it "if given reasonable preference is yes a reason must be selected" do - expect { + expect { CaseLog.create!(reasonable_preference: "Yes", - reasonable_preference_reason_homeless: nil, - reasonable_preference_reason_unsatisfactory_housing: nil, - reasonable_preference_reason_medical_grounds: nil, - reasonable_preference_reason_avoid_hardship: nil, - reasonable_preference_reason_do_not_know: nil - ) + reasonable_preference_reason_homeless: nil, + reasonable_preference_reason_unsatisfactory_housing: nil, + reasonable_preference_reason_medical_grounds: nil, + reasonable_preference_reason_avoid_hardship: nil, + reasonable_preference_reason_do_not_know: nil) }.to raise_error(ActiveRecord::RecordInvalid) end it "if not previously homeless reasonable preference should not be selected" do - expect { + expect { CaseLog.create!( homelessness: "No", - reasonable_preference: "Yes" - ) + reasonable_preference: "Yes", + ) }.to raise_error(ActiveRecord::RecordInvalid) end it "if not given reasonable preference a reason should not be selected" do - expect { + expect { CaseLog.create!( homelessness: "Yes", reasonable_preference: "No", - reasonable_preference_reason_homeless: true + reasonable_preference_reason_homeless: true, ) }.to raise_error(ActiveRecord::RecordInvalid) end