Browse Source

linting fixes

pull/25/head
MadeTech Dushan 4 years ago
parent
commit
8f2d9ddf81
  1. 14
      app/controllers/case_logs_controller.rb
  2. 16
      app/helpers/check_answers_helper.rb
  3. 20
      spec/features/case_log_spec.rb
  4. 2
      spec/helpers/check_answers_helper_spec.rb

14
app/controllers/case_logs_controller.rb

@ -29,11 +29,11 @@ class CaseLogsController < ApplicationController
@case_log.update!(answers_for_page) @case_log.update!(answers_for_page)
next_page = form.next_page(previous_page) next_page = form.next_page(previous_page)
redirect_path = if next_page == :check_answers redirect_path = if next_page == :check_answers
subsection = form.subsection_for_page(previous_page) subsection = form.subsection_for_page(previous_page)
"case_log_#{subsection}_check_answers_path" "case_log_#{subsection}_check_answers_path"
else else
"case_log_#{next_page}_path" "case_log_#{next_page}_path"
end end
redirect_to(send(redirect_path, @case_log)) redirect_to(send(redirect_path, @case_log))
end end
@ -41,8 +41,8 @@ class CaseLogsController < ApplicationController
def check_answers def check_answers
@case_log = CaseLog.find(params[:case_log_id]) @case_log = CaseLog.find(params[:case_log_id])
form = Form.new(2021, 2022) form = Form.new(2021, 2022)
current_url = request.env['PATH_INFO'] current_url = request.env["PATH_INFO"]
subsection = current_url.split('/')[-2] subsection = current_url.split("/")[-2]
subsection_pages = form.pages_for_subsection(subsection) subsection_pages = form.pages_for_subsection(subsection)
render "form/check_answers", locals: { case_log: @case_log, subsection_pages: subsection_pages } render "form/check_answers", locals: { case_log: @case_log, subsection_pages: subsection_pages }
end end

16
app/helpers/check_answers_helper.rb

@ -19,13 +19,13 @@ module CheckAnswersHelper
end end
def create_next_missing_question_link(case_log_id, subsection_pages, case_log) def create_next_missing_question_link(case_log_id, subsection_pages, case_log)
pages_to_fill_in = [] pages_to_fill_in = []
subsection_pages.each do |page_title, page_info| subsection_pages.each do |page_title, page_info|
page_info["questions"].any? { |q| case_log["q"].blank?} page_info["questions"].any? { |_q| case_log["q"].blank? }
pages_to_fill_in << page_title pages_to_fill_in << page_title
end end
url = "/case_logs/#{case_log_id}/#{pages_to_fill_in.first}" url = "/case_logs/#{case_log_id}/#{pages_to_fill_in.first}"
link_to('Answer the missing questions', url, class: "govuk-link").html_safe link_to("Answer the missing questions", url, class: "govuk-link").html_safe
end end
def display_answered_questions_summary(subsection_pages, case_log) def display_answered_questions_summary(subsection_pages, case_log)
@ -33,7 +33,7 @@ module CheckAnswersHelper
"<p>You answered all the questions</p>".html_safe "<p>You answered all the questions</p>".html_safe
else else
"<p>You answered #{get_answered_questions_total(subsection_pages, case_log)} of #{get_total_number_of_questions(subsection_pages)} questions</p> "<p>You answered #{get_answered_questions_total(subsection_pages, case_log)} of #{get_total_number_of_questions(subsection_pages)} questions</p>
#{create_next_missing_question_link(case_log["id"], subsection_pages, case_log)}".html_safe #{create_next_missing_question_link(case_log['id'], subsection_pages, case_log)}".html_safe
end end
end end

20
spec/features/case_log_spec.rb

@ -104,13 +104,13 @@ RSpec.describe "Test Features" do
context "when the user needs to check their answers for a subsection" do context "when the user needs to check their answers for a subsection" do
def fill_in_number_question(case_log_id, question, value) def fill_in_number_question(case_log_id, question, value)
visit("/case_logs/#{case_log_id}/#{question}") visit("/case_logs/#{case_log_id}/#{question}")
fill_in("#{question}", with: value) fill_in(question.to_s, with: value)
click_button("Save and continue") click_button("Save and continue")
end end
def answer_all_questions_in_income_subsection def answer_all_questions_in_income_subsection
visit("/case_logs/#{empty_case_log.id}/net_income") visit("/case_logs/#{empty_case_log.id}/net_income")
fill_in("net_income", with: 18000) fill_in("net_income", with: 18_000)
choose("net-income-frequency-yearly-field") choose("net-income-frequency-yearly-field")
click_button("Save and continue") click_button("Save and continue")
choose("net-income-uc-proportion-all-field") choose("net-income-uc-proportion-all-field")
@ -151,7 +151,7 @@ RSpec.describe "Test Features" do
visit("case_logs/#{empty_case_log.id}/#{subsection}/check_answers") visit("case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
assert_selector "a", text: /Answer\z/, count: 7 assert_selector "a", text: /Answer\z/, count: 7
assert_selector "a", text: "Change", count: 0 assert_selector "a", text: "Change", count: 0
expect(page).to have_link('Answer', href: "/case_logs/#{empty_case_log.id}/tenant_age") expect(page).to have_link("Answer", href: "/case_logs/#{empty_case_log.id}/tenant_age")
end end
it "should have a change link for answered questions" do it "should have a change link for answered questions" do
@ -159,26 +159,26 @@ RSpec.describe "Test Features" do
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers") visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
assert_selector "a", text: /Answer\z/, count: 6 assert_selector "a", text: /Answer\z/, count: 6
assert_selector "a", text: "Change", count: 1 assert_selector "a", text: "Change", count: 1
expect(page).to have_link('Change', href: "/case_logs/#{empty_case_log.id}/tenant_age") expect(page).to have_link("Change", href: "/case_logs/#{empty_case_log.id}/tenant_age")
end end
it "should have a link pointing to the first question if no questions are answered" do it "should have a link pointing to the first question if no questions are answered" do
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers") visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
expect(page).to have_content('You answered 0 of 7 questions') expect(page).to have_content("You answered 0 of 7 questions")
expect(page).to have_link('Answer the missing questions', href: "/case_logs/#{empty_case_log.id}/tenant_code") expect(page).to have_link("Answer the missing questions", href: "/case_logs/#{empty_case_log.id}/tenant_code")
end end
it "should have a link pointing to the next empty question if some questions are answered" do it "should have a link pointing to the next empty question if some questions are answered" do
fill_in_number_question(empty_case_log.id, "net_income", 18000) fill_in_number_question(empty_case_log.id, "net_income", 18_000)
visit("/case_logs/#{empty_case_log.id}/income_and_benefits/check_answers") visit("/case_logs/#{empty_case_log.id}/income_and_benefits/check_answers")
expect(page).to have_content('You answered 1 of 4 questions') expect(page).to have_content("You answered 1 of 4 questions")
expect(page).to have_link('Answer the missing questions', href: "/case_logs/#{empty_case_log.id}/net_income") expect(page).to have_link("Answer the missing questions", href: "/case_logs/#{empty_case_log.id}/net_income")
end end
it "should not display the missing answer questions link if all questions are answered" do it "should not display the missing answer questions link if all questions are answered" do
answer_all_questions_in_income_subsection answer_all_questions_in_income_subsection
expect(page).to have_content('You answered all the questions') expect(page).to have_content("You answered all the questions")
assert_selector "a", text: "Answer the missing questions", count: 0 assert_selector "a", text: "Answer the missing questions", count: 0
end end
end end

2
spec/helpers/check_answers_helper_spec.rb

@ -22,7 +22,7 @@ RSpec.describe CheckAnswersHelper do
subsection_pages = @form.pages_for_subsection("income_and_benefits") subsection_pages = @form.pages_for_subsection("income_and_benefits")
it "returns the total number of questions for a subsection" do it "returns the total number of questions for a subsection" do
expect(get_total_number_of_questions(subsection_pages)).to eq(4) expect(get_total_number_of_questions(subsection_pages)).to eq(4)
end end
end end
end end

Loading…
Cancel
Save