From 330126d6720a42649e3942b5f0d4410e3dc4b736 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Wed, 3 Aug 2016 10:46:03 -0500 Subject: [PATCH] fixes #30 - edit from summary with out js --- app/controllers/candidate_controller.rb | 6 ++--- app/views/candidate/question.html.erb | 2 +- app/views/candidate/summary.html.erb | 2 +- test/integration/question_flow_test.rb | 34 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 test/integration/question_flow_test.rb diff --git a/app/controllers/candidate_controller.rb b/app/controllers/candidate_controller.rb index f543d96..59fd244 100644 --- a/app/controllers/candidate_controller.rb +++ b/app/controllers/candidate_controller.rb @@ -26,14 +26,14 @@ class CandidateController < ApplicationController end def question - qid = prep_status.current_question_id + qid = prep_status.current_question_id || params[:question_id] redirect_to :summary and return if qid.nil? prep_question qid prep_instance_answer @question end def update_answer - qid = params[:qid] ||= prep_status.current_question_id + qid = answer_params[:question_id] || prep_status.current_question_id @answer = prep_answer qid send "process_#{prep_question(qid).input_type}" end @@ -114,7 +114,7 @@ class CandidateController < ApplicationController render :question else # TODO: change params.key? to submit = save/next/summary - redirect_to :summary and return if params.key?(:update) + # redirect_to :summary and return if params.key?(:update) redirect_to :saved and return if params.key?(:save) redirect_to :question end diff --git a/app/views/candidate/question.html.erb b/app/views/candidate/question.html.erb index 26e7054..23fb9ba 100644 --- a/app/views/candidate/question.html.erb +++ b/app/views/candidate/question.html.erb @@ -22,7 +22,7 @@ <% if @status.on_summary %>
- +
<% else %> diff --git a/app/views/candidate/summary.html.erb b/app/views/candidate/summary.html.erb index c9e4874..208a2a0 100644 --- a/app/views/candidate/summary.html.erb +++ b/app/views/candidate/summary.html.erb @@ -6,7 +6,7 @@

<% @quiz.each do |question| %> - <%= form_for(:answer, url: post_answer_path(answer_id: question.answer_id, qid: question.question_id), html:{class: 'summary-form'}) do |form| %> + <%= form_for(:answer, url: post_answer_path(answer_id: question.answer_id), html:{class: 'summary-form'}) do |form| %>
diff --git a/test/integration/question_flow_test.rb b/test/integration/question_flow_test.rb new file mode 100644 index 0000000..048ea0b --- /dev/null +++ b/test/integration/question_flow_test.rb @@ -0,0 +1,34 @@ +require 'test_helper' + +class QuestionFlowTest < ActionDispatch::IntegrationTest + def setup_auth candidate + post validate_candidate_url, params: { test_id: candidate.test_hash } + end + + test "should load the first question" do + setup_auth candidates(:martha) + + get question_path + assert_response :success + assert_select '.question-text', questions(:fed1).question + end + + test "should load the summary" do + setup_auth candidates(:dawn) + + get summary_path + assert_response :success + assert_select '.prft-heading', 'Almost done!' + end + + test "can load specific question from summary" do + setup_auth candidates(:dawn) + question = questions(:fed4) + + get question_path(question.id) + assert_response :success + assert_select '.question-text', question.question + # TODO: add in capybara and test form post + # assert_redirected summary_path + end +end