Browse Source

small refactors and rubocop

pull/49/head
Kat 4 years ago
parent
commit
71b0a285ec
  1. 4
      app/controllers/case_logs_controller.rb
  2. 20
      app/helpers/check_answers_helper.rb
  3. 2
      app/views/form/_check_answers_table.html.erb
  4. 2
      db/schema.rb
  5. 7
      spec/models/case_log_spec.rb

4
app/controllers/case_logs_controller.rb

@ -134,13 +134,11 @@ 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])
if responses_for_page[question].present? && answer.include?(responses_for_page[question])
return "case_log_#{route}_path"
end
end
end
end
next unless content.key?("next_page")

20
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

2
app/views/form/_check_answers_table.html.erb

@ -1,7 +1,7 @@
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= question_info["check_answer_label"].to_s != "" ? question_info["check_answer_label"].to_s : question_info["header"].to_s%>
<%= question_info["check_answer_label"].to_s.present? ? question_info["check_answer_label"].to_s : question_info["header"].to_s%>
<dt>
<dd class="govuk-summary-list__value">
<%= @case_log[question_title] %>

2
db/schema.rb

@ -84,6 +84,7 @@ ActiveRecord::Schema.define(version: 2021_10_15_090040) do
t.string "property_void_date"
t.string "property_major_repairs"
t.string "property_major_repairs_date"
t.integer "property_number_of_times_relet"
t.string "property_wheelchair_accessible"
t.string "net_income"
t.string "net_income_frequency"
@ -131,7 +132,6 @@ ActiveRecord::Schema.define(version: 2021_10_15_090040) do
t.boolean "reasonable_preference_reason_avoid_hardship"
t.boolean "reasonable_preference_reason_do_not_know"
t.datetime "discarded_at"
t.integer "property_number_of_times_relet"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
end

7
spec/models/case_log_spec.rb

@ -34,8 +34,7 @@ RSpec.describe Form, type: :model do
reasonable_preference_reason_unsatisfactory_housing: nil,
reasonable_preference_reason_medical_grounds: nil,
reasonable_preference_reason_avoid_hardship: nil,
reasonable_preference_reason_do_not_know: nil
)
reasonable_preference_reason_do_not_know: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -43,7 +42,7 @@ RSpec.describe Form, type: :model do
expect {
CaseLog.create!(
homelessness: "No",
reasonable_preference: "Yes"
reasonable_preference: "Yes",
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -53,7 +52,7 @@ RSpec.describe Form, type: :model do
CaseLog.create!(
homelessness: "Yes",
reasonable_preference: "No",
reasonable_preference_reason_homeless: true
reasonable_preference_reason_homeless: true,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end

Loading…
Cancel
Save