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 @@