diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 23bf8f514..9dffdc533 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -37,7 +37,6 @@ class CaseLogsController < ApplicationController def check_answers @case_log = CaseLog.find(params[:case_log_id]) - form = Form.new(2021, 2022) current_url = request.env["PATH_INFO"] subsection = current_url.split("/")[-2] render "form/check_answers", locals: { case_log: @case_log, subsection: subsection } diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index ab46812c7..a2c45f7a5 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -12,7 +12,6 @@ module CheckAnswersHelper def total_questions(subsection, case_log) form = Form.new(2021, 2022) questions = form.questions_for_subsection(subsection) - question_keys = questions.keys questions_not_applicable = [] questions.reject do |question_key, question| question.fetch("conditional_for", []).map do |conditional_question_key, condition| @@ -25,12 +24,12 @@ module CheckAnswersHelper end def condition_not_met(case_log, question_key, condition) - case_log[question_key].blank? || !(eval(case_log[question_key].to_s + condition)) + case_log[question_key].blank? || !eval(case_log[question_key].to_s + condition) end def subsection_pages(subsection) - @form ||= Form.new(2021, 2022) - @subsection_pages ||= @form.pages_for_subsection(subsection) + form = Form.new(2021, 2022) + form.pages_for_subsection(subsection) end def create_update_answer_link(case_log_answer, case_log_id, page) @@ -49,7 +48,6 @@ module CheckAnswersHelper end def display_answered_questions_summary(subsection, case_log) - # binding.pry if total_answered_questions(subsection, case_log) == total_number_of_questions(subsection, case_log) '

You answered all the questions

'.html_safe else diff --git a/app/helpers/stimulus_controller_attribute_helper.rb b/app/helpers/stimulus_controller_attribute_helper.rb index 825c0dde0..fe254e85b 100644 --- a/app/helpers/stimulus_controller_attribute_helper.rb +++ b/app/helpers/stimulus_controller_attribute_helper.rb @@ -2,12 +2,12 @@ module StimulusControllerAttributeHelper def stimulus_html_attributes(question) attribs = [ numeric_question_html_attributes(question), - conditional_html_attributes(question) + conditional_html_attributes(question), ] merge_controller_attributes(*attribs) end - private +private def numeric_question_html_attributes(question) return {} if question["fields-to-add"].blank? || question["result-field"].blank? diff --git a/config/routes.rb b/config/routes.rb index 609124146..4f9db913d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ Rails.application.routes.draw do get "about", to: "about#index" get "/", to: "test#index" - post '/case_logs/:id', to: "case_logs#submit_form" + post "/case_logs/:id", to: "case_logs#submit_form" form = Form.new(2021, 2022) resources :case_logs do diff --git a/spec/helpers/stimulus_controller_attribute_helper_spec.rb b/spec/helpers/stimulus_controller_attribute_helper_spec.rb index e0dcbe551..3ae54d305 100644 --- a/spec/helpers/stimulus_controller_attribute_helper_spec.rb +++ b/spec/helpers/stimulus_controller_attribute_helper_spec.rb @@ -19,30 +19,30 @@ RSpec.describe StimulusControllerAttributeHelper do end context "a question that requires multiple controllers" do - let(:question) { + let(:question) do { - "check_answer_label"=>"Basic Rent", - "header"=>"What is the basic rent?", - "hint_text"=>"Eligible for housing benefit or Universal Credit", - "type"=>"numeric", - "min"=>0, - "step"=>1, - "fields-to-add"=>["basic_rent", "service_charge", "personal_service_charge", "support_charge"], - "result-field"=>"total_charge", + "check_answer_label" => "Basic Rent", + "header" => "What is the basic rent?", + "hint_text" => "Eligible for housing benefit or Universal Credit", + "type" => "numeric", + "min" => 0, + "step" => 1, + "fields-to-add" => %w[basic_rent service_charge personal_service_charge support_charge], + "result-field" => "total_charge", "conditional_for" => { - "next_question": ">1" - } + "next_question": ">1", + }, } - } - let(:expected_attribs) { + end + let(:expected_attribs) do { "data-controller": "numeric-question conditional-question", "data-action": "numeric-question#calculateFields conditional-question#displayConditional", "data-target": "case-log-#{question['result-field'].to_s.dasherize}-field", "data-calculated": question["fields-to-add"].to_json, - "data-info": question["conditional_for"].to_json + "data-info": question["conditional_for"].to_json, } - } + end it "correctly merges html attributes" do expect(stimulus_html_attributes(question)).to eq(expected_attribs) end