Browse Source

Refactor special case into question

pull/187/head
baarkerlounger 3 years ago
parent
commit
adf471211a
  1. 2
      Gemfile.lock
  2. 7
      app/models/form/question.rb
  3. 7
      app/models/form/subsection.rb

2
Gemfile.lock

@ -357,7 +357,7 @@ GEM
simplecov_json_formatter (0.1.3) simplecov_json_formatter (0.1.3)
stimulus-rails (1.0.2) stimulus-rails (1.0.2)
railties (>= 6.0.0) railties (>= 6.0.0)
thor (1.1.0) thor (1.2.1)
turbo-rails (1.0.0) turbo-rails (1.0.0)
actionpack (>= 6.0.0) actionpack (>= 6.0.0)
railties (>= 6.0.0) railties (>= 6.0.0)

7
app/models/form/question.rb

@ -49,6 +49,13 @@ class Form::Question
end end
end end
def completed?(case_log)
# Special case as No is a valid answer but doesn't let you progress and use the service
return false if id == "gdpr_acceptance" && case_log[id] == "No"
case_log[id].present?
end
private private
def checkbox_answer_label(case_log) def checkbox_answer_label(case_log)

7
app/models/form/subsection.rb

@ -30,16 +30,11 @@ class Form::Subsection
qs = applicable_questions(case_log) qs = applicable_questions(case_log)
return :not_started if qs.all? { |question| case_log[question.id].blank? } return :not_started if qs.all? { |question| case_log[question.id].blank? }
return :completed if qs.all? { |question| case_log[question.id].present? } && !invalidated?(case_log) return :completed if qs.all? { |question| question.completed?(case_log) }
:in_progress :in_progress
end end
def invalidated?(case_log)
applicable_questions(case_log).map(&:id).include?("gdpr_acceptance") &&
case_log["gdpr_acceptance"] == "No"
end
def is_incomplete?(case_log) def is_incomplete?(case_log)
%i[not_started in_progress].include?(status(case_log)) %i[not_started in_progress].include?(status(case_log))
end end

Loading…
Cancel
Save