From 364aa6742e275943c63c5885ea315750b67f6790 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 4 Oct 2021 15:54:09 +0100 Subject: [PATCH] lint --- app/helpers/tasklist_helper.rb | 33 +++++++++++++++------------- app/models/form.rb | 2 +- spec/features/case_log_spec.rb | 3 +-- spec/helpers/tasklist_helper_spec.rb | 4 ++-- spec/models/form_spec.rb | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index e2363a9c3..d30dc0187 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -1,25 +1,26 @@ module TasklistHelper STATUSES = { - :not_started => "Not started", - :cannot_start_yet => "Cannot start yet", - :completed => "Completed", - :in_progress => "In progress" - } + not_started: "Not started", + cannot_start_yet: "Cannot start yet", + completed: "Completed", + in_progress: "In progress", + }.freeze STYLES = { - :not_started => "govuk-tag--grey", - :cannot_start_yet => "govuk-tag--grey", - :completed => "", - :in_progress => "govuk-tag--blue" - } + not_started: "govuk-tag--grey", + cannot_start_yet: "govuk-tag--grey", + completed: "", + in_progress: "govuk-tag--blue", + }.freeze def get_subsection_status(subsection_name, case_log, questions) if subsection_name == "declaration" return all_questions_completed(case_log) ? :not_started : :cannot_start_yet end - return :not_started if questions.all? {|question| case_log[question].blank?} - return :completed if questions.all? {|question| case_log[question].present?} + return :not_started if questions.all? { |question| case_log[question].blank? } + return :completed if questions.all? { |question| case_log[question].present? } + :in_progress end @@ -39,16 +40,18 @@ module TasklistHelper def get_sections_count(form, case_log, status = :all) subsections = form.all_subsections.keys return subsections.count if status == :all + subsections.count { |subsection| get_subsection_status(subsection, case_log, form.questions_for_subsection(subsection).keys) == status } end - private +private + def all_questions_completed(case_log) - case_log.attributes.all? { |_question, answer| answer.present?} + case_log.attributes.all? { |_question, answer| answer.present? } end def is_incomplete?(subsection, case_log, questions) status = get_subsection_status(subsection, case_log, questions) - status == :not_started || status == :in_progress + %i[not_started in_progress].include?(status) end end diff --git a/app/models/form.rb b/app/models/form.rb index 960b8ca1f..586df20f5 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -62,6 +62,6 @@ class Form end def questions_for_subsection(subsection) - pages_for_subsection(subsection).map {|title, _value| questions_for_page(title)}.reduce(:merge) + pages_for_subsection(subsection).map { |title, _value| questions_for_page(title) }.reduce(:merge) end end diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 76bcd72ed..8ae4b06b4 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -26,7 +26,6 @@ RSpec.describe "Test Features" do click_button("Save and continue") end - describe "Create new log" do it "redirects to the task list for the new log" do visit("/case_logs") @@ -63,7 +62,7 @@ RSpec.describe "Test Features" do it "skips to the first section if no answers are completed" do visit("/case_logs/#{empty_case_log.id}") - expect(page).to have_link("Skip to next incomplete section", :href => /#household_characteristics/) + expect(page).to have_link("Skip to next incomplete section", href: /#household_characteristics/) end it "shows the number of completed sections if no sections are completed" do diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index be08c939f..b8fbaae0f 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -25,13 +25,13 @@ RSpec.describe TasklistHelper do end it "returns completed if all the questions in the subsection have been answered" do - %w(net_income net_income_frequency net_income_uc_proportion housing_benefit).each {|x| case_log[x] = "value" } + %w[net_income net_income_frequency net_income_uc_proportion housing_benefit].each { |x| case_log[x] = "value" } status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions) expect(status).to eq(:completed) end it "returns not started if the subsection is declaration and all the questions are completed" do - completed_case_log = CaseLog.new(case_log.attributes.map { |key, value| Hash[key, value || "value"] }.reduce(:merge)) + completed_case_log = CaseLog.new(case_log.attributes.map { |key, value| Hash[key, value || "value"] }.reduce(:merge)) status = get_subsection_status("declaration", completed_case_log, declaration_questions) expect(status).to eq(:not_started) end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 2a6c00d8c..019c483ce 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Form, type: :model do it "returns all questions for subsection" do result = form.questions_for_subsection(subsection) expect(result.length).to eq(4) - expect(result.keys).to eq(["net_income", "net_income_frequency", "net_income_uc_proportion", "housing_benefit"]) + expect(result.keys).to eq(%w[net_income net_income_frequency net_income_uc_proportion housing_benefit]) end end end