From 47e17e2a3c4e71fad86bc8446d9c639b691dbe65 Mon Sep 17 00:00:00 2001 From: MadeTech Dushan Date: Fri, 28 Jan 2022 15:20:46 +0000 Subject: [PATCH] some basic extract method refactors --- app/models/form.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/models/form.rb b/app/models/form.rb index 4a2687752..dc643b89f 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -51,11 +51,26 @@ class Form subsection_ids = subsections.map(&:id) if case_log.status == "completed" || all_subsections_except_declaration_completed?(case_log) - next_subsection = get_subsection(subsection_ids[subsection_ids.length - 1]) + return first_question_in_last_subsection(subsection_ids) + end + + next_subsection = next_subsection(subsection, case_log, subsection_ids) + + if next_subsection.status(case_log) == :completed + next_incomplete_section_redirect_path(next_subsection, case_log) + else first_question_in_subsection = next_subsection.pages.first.id - return first_question_in_subsection.to_s.dasherize + first_question_in_subsection.to_s.dasherize end + end + def first_question_in_last_subsection(subsection_ids) + next_subsection = get_subsection(subsection_ids[subsection_ids.length - 1]) + first_question_in_subsection = next_subsection.pages.first.id + return first_question_in_subsection.to_s.dasherize + end + + def next_subsection(subsection, case_log, subsection_ids) next_subsection_id_index = subsection_ids.index(subsection.id) + 1 next_subsection = get_subsection(subsection_ids[next_subsection_id_index]) @@ -63,12 +78,7 @@ class Form next_subsection = get_subsection(subsection_ids[0]) end - if next_subsection.status(case_log) == :completed - next_incomplete_section_redirect_path(next_subsection, case_log) - else - first_question_in_subsection = next_subsection.pages.first.id - first_question_in_subsection.to_s.dasherize - end + return next_subsection end def all_subsections_except_declaration_completed?(case_log)