From 918b67e6e944484208b98e6eeb55545fe0e500e0 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Thu, 2 Feb 2023 12:40:40 +0000 Subject: [PATCH] bulk upload CYA missing answers always red - whereas previosly this only happened if user was filtering logs via a bulk upload --- Gemfile | 1 - Gemfile.lock | 5 --- ...eck_answers_summary_list_card_component.rb | 11 ++++--- app/controllers/form_controller.rb | 7 ----- app/controllers/lettings_logs_controller.rb | 4 +-- app/views/form/check_answers.html.erb | 2 +- ...nswers_summary_list_card_component_spec.rb | 16 ++++++++-- spec/controllers/form_controller_spec.rb | 31 ------------------- 8 files changed, 23 insertions(+), 54 deletions(-) delete mode 100644 spec/controllers/form_controller_spec.rb diff --git a/Gemfile b/Gemfile index 22461ee2a..02bcdf3b7 100644 --- a/Gemfile +++ b/Gemfile @@ -91,7 +91,6 @@ group :test do gem "capybara-lockstep" gem "factory_bot_rails" gem "faker" - gem "rails-controller-testing" gem "rspec-rails", require: false gem "selenium-webdriver", require: false gem "simplecov", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 423fc26f1..cb46ee64a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -289,10 +289,6 @@ GEM activesupport (= 7.0.4.1) bundler (>= 1.15.0) railties (= 7.0.4.1) - rails-controller-testing (1.0.5) - actionpack (>= 5.0.1.rc1) - actionview (>= 5.0.1.rc1) - activesupport (>= 5.0.1.rc1) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -471,7 +467,6 @@ DEPENDENCIES rack-attack rack-mini-profiler (~> 2.0) rails (~> 7.0.2) - rails-controller-testing redis roo rspec-rails diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index ad22d9e92..874ac8c10 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -1,11 +1,10 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base - attr_reader :questions, :log, :user, :bulk_upload + attr_reader :questions, :log, :user - def initialize(questions:, log:, user:, bulk_upload: nil) + def initialize(questions:, log:, user:) @questions = questions @log = log @user = user - @bulk_upload = bulk_upload super end @@ -39,13 +38,17 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base private def unanswered_value - if bulk_upload + if bulk_uploaded? "You still need to answer this question".html_safe else "You didn’t answer this question".html_safe end end + def bulk_uploaded? + log.bulk_upload + end + def number_of_buyers log[:jointpur] == 1 ? 2 : 1 end diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 276faf8f6..24e3d1b32 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -4,8 +4,6 @@ class FormController < ApplicationController before_action :find_resource_by_named_id, except: %i[submit_form review] before_action :check_collection_period, only: %i[submit_form show_page] - before_action :extract_bulk_upload_from_session_filters, only: [:check_answers] - def submit_form if @log @page = form.get_page(params[@log.model_name.param_key][:page]) @@ -65,11 +63,6 @@ class FormController < ApplicationController private - def extract_bulk_upload_from_session_filters - filter_service = FilterService.new(current_user:, session:) - @bulk_upload = filter_service.bulk_upload - end - def restore_error_field_values if session["errors"] JSON(session["errors"]).each do |field, messages| diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index a7bc2dc56..5181d21ca 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/app/controllers/lettings_logs_controller.rb @@ -119,8 +119,8 @@ private end def extract_bulk_upload_from_session_filters - id = ((@session_filters["bulk_upload_id"] || []).reject(&:blank?))[0] - @bulk_upload = current_user.bulk_uploads.find_by(id:) + filter_service = FilterService.new(current_user:, session:) + @bulk_upload = filter_service.bulk_upload end def permitted_log_params diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index bf7f68e82..46a945017 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -19,7 +19,7 @@ <% if any_questions_have_summary_card_number?(subsection, @log) %> <% subsection.applicable_questions(@log).group_by(&:check_answers_card_number).values.each do |question_group| %> - <%= render CheckAnswersSummaryListCardComponent.new(questions: question_group, log: @log, user: current_user, bulk_upload: @bulk_upload) %> + <%= render CheckAnswersSummaryListCardComponent.new(questions: question_group, log: @log, user: current_user) %> <% end %> <% else %> <%= render partial: "form/check_answers_summary_list", locals: { diff --git a/spec/components/check_answers_summary_list_card_component_spec.rb b/spec/components/check_answers_summary_list_card_component_spec.rb index ece39360a..f9b8f6667 100644 --- a/spec/components/check_answers_summary_list_card_component_spec.rb +++ b/spec/components/check_answers_summary_list_card_component_spec.rb @@ -25,15 +25,25 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do expect(component.get_answer_label(sex1_question)).to eq("Female") end - context "when filtered by bulk upload with unanswered question" do - subject(:component) { described_class.new(questions:, log:, user:, bulk_upload:) } + context "when log was created via a bulk upload and has an unanswered question" do + subject(:component) { described_class.new(questions:, log:, user:) } let(:bulk_upload) { build(:bulk_upload, :lettings) } let(:log) { build(:lettings_log, :in_progress, bulk_upload:, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } - it "is displayed with tweaked copy in red" do + it "displays tweaked copy in red" do expect(rendered).to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question") end end + + context "when log was not created via a bulk upload and has an unanswered question" do + subject(:component) { described_class.new(questions:, log:, user:) } + + let(:log) { build(:lettings_log, :in_progress, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } + + it "displays normal copy with muted colour " do + expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question") + end + end end end diff --git a/spec/controllers/form_controller_spec.rb b/spec/controllers/form_controller_spec.rb deleted file mode 100644 index 3b9e5c016..000000000 --- a/spec/controllers/form_controller_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require "rails_helper" - -RSpec.describe FormController do - before do - sign_in user - end - - describe "GET #check_answers /lettings-logs/:ID/:SECTION_ID/check-answers" do - let(:user) { create(:user) } - let(:bulk_upload) { create(:bulk_upload, :lettings, user:) } - let(:log) { create(:lettings_log, bulk_upload:) } - - context "when checking answers without bulk upload " do - it "assigns @bulk_upload to nil" do - get :check_answers, params: { lettings_log_id: log.id } - - expect(assigns(:bulk_upload)).to be_nil - end - end - - context "when checking answers with bulk upload " do - it "assigns @bulk_upload" do - session[:logs_filters] = { bulk_upload_id: [bulk_upload.id.to_s] }.to_json - - get :check_answers, params: { lettings_log_id: log.id } - - expect(assigns(:bulk_upload)).to eql(bulk_upload) - end - end - end -end