Browse Source

Make total number of questions work with conditional routing and run rubocop

pull/49/head
Kat 4 years ago
parent
commit
7b96e60650
  1. 12
      app/controllers/case_logs_controller.rb
  2. 5
      app/helpers/check_answers_helper.rb
  3. 2
      app/models/form_handler.rb
  4. 13
      spec/helpers/check_answers_helper_spec.rb

12
app/controllers/case_logs_controller.rb

@ -97,14 +97,14 @@ private
params.require(:case_log).permit(CaseLog.editable_fields)
end
def get_next_page_path(form, previous_page, responses_for_page={})
def get_next_page_path(form, previous_page, responses_for_page = {})
questions_for_page = form.questions_for_page(previous_page)
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] == answer
return "case_log_#{route.to_s}_path"
end
next unless content.key?("conditional_route_to")
content["conditional_route_to"].each do |route, answer|
if responses_for_page[question] == answer
return "case_log_#{route}_path"
end
end
end

5
app/helpers/check_answers_helper.rb

@ -18,6 +18,11 @@ module CheckAnswersHelper
questions_not_applicable << conditional_question_key
end
end
question.fetch("conditional_route_to", []).map do |conditional_page_key, condition|
if condition_not_met(case_log, question_key, question, condition)
questions_not_applicable += form.questions_for_page(conditional_page_key).keys
end
end
questions_not_applicable.include?(question_key)
end
end

2
app/models/form_handler.rb

@ -12,8 +12,8 @@ class FormHandler
@forms[form] ||= Form.new(form)
end
private
private
def get_all_forms
forms = {}
directories = ["config/forms", "spec/fixtures/forms"]

13
spec/helpers/check_answers_helper_spec.rb

@ -111,10 +111,19 @@ RSpec.describe CheckAnswersHelper do
end
context "conditional routing" do
xit "ignores not visited questions when no questions are answered" do
it "ignores not visited questions when no questions are answered" do
expect(total_number_of_questions(conditional_routing_subsection, case_log, form)).to eq(1)
end
end
it "counts correct questions when the conditional question is answered" do
case_log["pregnancy"] = "Yes"
expect(total_number_of_questions(conditional_routing_subsection, case_log, form)).to eq(2)
end
it "counts correct questions when the conditional question is answered" do
case_log["pregnancy"] = "No"
expect(total_number_of_questions(conditional_routing_subsection, case_log, form)).to eq(2)
end
end
end
end

Loading…
Cancel
Save