From f60df929493aafd0c11404602c39ad468d4ea11c Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 7 Sep 2022 11:49:49 +0100 Subject: [PATCH] Move redundant methods to log parent class --- app/models/lettings_log.rb | 21 --------------------- app/models/log.rb | 23 +++++++++++++++++++++++ app/models/sales_log.rb | 23 ----------------------- 3 files changed, 23 insertions(+), 44 deletions(-) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 81c69f1f5..8c58281ab 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -528,16 +528,6 @@ private PIO = PostcodeService.new - def update_status! - self.status = if all_fields_completed? && errors.empty? - "completed" - elsif all_fields_nil? - "not_started" - else - "in_progress" - end - end - def reset_not_routed_questions enabled_questions = form.enabled_page_questions(self) enabled_question_ids = enabled_questions.map(&:id) @@ -689,17 +679,6 @@ private end end - def all_fields_completed? - subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq - subsection_statuses == [:completed] - end - - def all_fields_nil? - not_started_statuses = %i[not_started cannot_start_yet] - subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq - subsection_statuses.all? { |status| not_started_statuses.include?(status) } - end - def age_refused? [age1_known, age2_known, age3_known, age4_known, age5_known, age6_known, age7_known, age8_known].any?(1) end diff --git a/app/models/log.rb b/app/models/log.rb index 316af6d06..bb645bf52 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -4,4 +4,27 @@ class Log < ApplicationRecord belongs_to :owning_organisation, class_name: "Organisation", optional: true belongs_to :managing_organisation, class_name: "Organisation", optional: true belongs_to :created_by, class_name: "User", optional: true + +private + + def update_status! + self.status = if all_fields_completed? && errors.empty? + "completed" + elsif all_fields_nil? + "not_started" + else + "in_progress" + end + end + + def all_fields_completed? + subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq + subsection_statuses == [:completed] + end + + def all_fields_nil? + not_started_statuses = %i[not_started cannot_start_yet] + subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq + subsection_statuses.all? { |status| not_started_statuses.include?(status) } + end end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 28c47952b..8417c8e5b 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -46,27 +46,4 @@ class SalesLog < Log def completed? status == "completed" end - -private - - def update_status! - self.status = if all_fields_completed? && errors.empty? - "completed" - elsif all_fields_nil? - "not_started" - else - "in_progress" - end - end - - def all_fields_completed? - subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq - subsection_statuses == [:completed] - end - - def all_fields_nil? - not_started_statuses = %i[not_started cannot_start_yet] - subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq - subsection_statuses.all? { |status| not_started_statuses.include?(status) } - end end