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. 6
      app/controllers/case_logs_controller.rb
  2. 5
      app/helpers/check_answers_helper.rb
  3. 2
      app/models/form_handler.rb
  4. 11
      spec/helpers/check_answers_helper_spec.rb

6
app/controllers/case_logs_controller.rb

@ -100,11 +100,11 @@ private
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 = form.questions_for_page(previous_page)
questions_for_page.each do |question, content| questions_for_page.each do |question, content|
if(content.key?("conditional_route_to")) next unless content.key?("conditional_route_to")
content["conditional_route_to"].each do |route, answer| content["conditional_route_to"].each do |route, answer|
if responses_for_page[question] == answer if responses_for_page[question] == answer
return "case_log_#{route.to_s}_path" return "case_log_#{route}_path"
end
end end
end end
end end

5
app/helpers/check_answers_helper.rb

@ -18,6 +18,11 @@ module CheckAnswersHelper
questions_not_applicable << conditional_question_key questions_not_applicable << conditional_question_key
end end
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) questions_not_applicable.include?(question_key)
end end
end end

2
app/models/form_handler.rb

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

11
spec/helpers/check_answers_helper_spec.rb

@ -111,10 +111,19 @@ RSpec.describe CheckAnswersHelper do
end end
context "conditional routing" do 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) 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 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
end end

Loading…
Cancel
Save