From c880c980c33f28a23c2db1ae70c19fb4bc71197f Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 29 Nov 2021 18:07:52 +0000 Subject: [PATCH] Update feature specs --- spec/controllers/case_logs_controller_spec.rb | 20 ++++++++----- spec/features/form/check_answers_page_spec.rb | 20 +++++++++++-- .../form/conditional_questions_spec.rb | 14 +++++++-- spec/features/form/form_navigation_spec.rb | 16 ++++++---- spec/features/form/helpers.rb | 7 +++++ spec/features/form/page_routing_spec.rb | 14 +++++++-- spec/features/form/saving_data_spec.rb | 18 +++++++++-- spec/features/form/tasklist_page_spec.rb | 20 +++++++++++-- spec/features/form/validations_spec.rb | 30 ++++++++++++++++--- 9 files changed, 130 insertions(+), 29 deletions(-) diff --git a/spec/controllers/case_logs_controller_spec.rb b/spec/controllers/case_logs_controller_spec.rb index 0acffe52c..1f31b7e1c 100644 --- a/spec/controllers/case_logs_controller_spec.rb +++ b/spec/controllers/case_logs_controller_spec.rb @@ -1,9 +1,20 @@ require "rails_helper" -require_relative "../support/devise" RSpec.describe CaseLogsController, type: :controller do let(:valid_session) { {} } - login_user + let(:user) { FactoryBot.create(:user) } + let(:case_log) do + FactoryBot.create( + :case_log, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end + let(:id) { case_log.id } + + before do + sign_in user + end context "Collection routes" do describe "GET #index" do @@ -37,9 +48,6 @@ RSpec.describe CaseLogsController, type: :controller do end context "Instance routes" do - let!(:case_log) { FactoryBot.create(:case_log) } - let(:id) { case_log.id } - describe "GET #show" do it "returns a success response" do get :show, params: { id: id } @@ -56,8 +64,6 @@ RSpec.describe CaseLogsController, type: :controller do end describe "submit_form" do - let!(:case_log) { FactoryBot.create(:case_log) } - let(:id) { case_log.id } let(:case_log_form_params) do { accessibility_requirements: %w[ housingneeds_a diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 2da1982a2..77641968b 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -3,12 +3,26 @@ require_relative "helpers" RSpec.describe "Form Check Answers Page" do include Helpers - let(:case_log) { FactoryBot.create(:case_log, :in_progress) } - let(:empty_case_log) { FactoryBot.create(:case_log) } + let(:user) { FactoryBot.create(:user) } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end + let(:empty_case_log) do + FactoryBot.create( + :case_log, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end let(:id) { case_log.id } before do - allow_any_instance_of(CaseLogsController).to receive(:authenticate_user!).and_return(true) + sign_in user end let(:subsection) { "household_characteristics" } diff --git a/spec/features/form/conditional_questions_spec.rb b/spec/features/form/conditional_questions_spec.rb index dc6193fa2..fca02ea78 100644 --- a/spec/features/form/conditional_questions_spec.rb +++ b/spec/features/form/conditional_questions_spec.rb @@ -1,11 +1,21 @@ require "rails_helper" +require_relative "helpers" RSpec.describe "Form Conditional Questions" do - let(:case_log) { FactoryBot.create(:case_log, :in_progress) } + include Helpers + let(:user) { FactoryBot.create(:user) } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end let(:id) { case_log.id } before do - allow_any_instance_of(CaseLogsController).to receive(:authenticate_user!).and_return(true) + sign_in user end context "given a page where some questions are only conditionally shown, depending on how you answer the first question" do diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb index 791d72643..f36238405 100644 --- a/spec/features/form/form_navigation_spec.rb +++ b/spec/features/form/form_navigation_spec.rb @@ -1,8 +1,17 @@ require "rails_helper" +require_relative "helpers" RSpec.describe "Form Navigation" do + include Helpers let(:user) { FactoryBot.create(:user) } - let(:case_log) { FactoryBot.create(:case_log, :in_progress) } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end let(:id) { case_log.id } let(:question_answers) do { @@ -14,10 +23,7 @@ RSpec.describe "Form Navigation" do end before do - visit("/case_logs") - fill_in("user_email", with: user.email) - fill_in("user_password", with: user.password) - click_button("Sign in") + sign_in user end describe "Create new log" do diff --git a/spec/features/form/helpers.rb b/spec/features/form/helpers.rb index e5ea8e173..e0c1631b4 100644 --- a/spec/features/form/helpers.rb +++ b/spec/features/form/helpers.rb @@ -15,4 +15,11 @@ module Helpers choose("case-log-hb-prefer-not-to-say-field") click_button("Save and continue") end + + def sign_in(user) + visit("/case_logs") + fill_in("user_email", with: user.email) + fill_in("user_password", with: user.password) + click_button("Sign in") + end end diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index 0a9146c61..96ad0bde8 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -1,12 +1,22 @@ require "rails_helper" +require_relative "helpers" RSpec.describe "Form Page Routing" do - let(:case_log) { FactoryBot.create(:case_log, :in_progress) } + include Helpers + let(:user) { FactoryBot.create(:user) } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end let(:id) { case_log.id } before do - allow_any_instance_of(CaseLogsController).to receive(:authenticate_user!).and_return(true) allow_any_instance_of(CaseLogValidator).to receive(:validate_pregnancy).and_return(true) + sign_in user end it "can route the user to a different page based on their answer on the current page", js: true do diff --git a/spec/features/form/saving_data_spec.rb b/spec/features/form/saving_data_spec.rb index 9a3b0cd41..2a9c6e3f9 100644 --- a/spec/features/form/saving_data_spec.rb +++ b/spec/features/form/saving_data_spec.rb @@ -1,13 +1,25 @@ require "rails_helper" +require_relative "helpers" RSpec.describe "Form Saving Data" do - let(:case_log) { FactoryBot.create(:case_log, :in_progress) } + include Helpers + let(:user) { FactoryBot.create(:user) } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end let(:id) { case_log.id } let(:case_log_with_checkbox_questions_answered) do FactoryBot.create( :case_log, :in_progress, housingneeds_a: "Yes", - housingneeds_c: "Yes" + housingneeds_c: "Yes", + owning_organisation: user.organisation, + managing_organisation: user.organisation ) end let(:question_answers) do @@ -20,7 +32,7 @@ RSpec.describe "Form Saving Data" do end before do - allow_any_instance_of(CaseLogsController).to receive(:authenticate_user!).and_return(true) + sign_in user end it "updates model attributes correctly for each question" do diff --git a/spec/features/form/tasklist_page_spec.rb b/spec/features/form/tasklist_page_spec.rb index 6248e5838..b9a4f4f84 100644 --- a/spec/features/form/tasklist_page_spec.rb +++ b/spec/features/form/tasklist_page_spec.rb @@ -3,13 +3,27 @@ require_relative "helpers" RSpec.describe "Task List" do include Helpers - let(:case_log) { FactoryBot.create(:case_log, :in_progress) } - let(:empty_case_log) { FactoryBot.create(:case_log) } + let(:user) { FactoryBot.create(:user) } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end + let(:empty_case_log) do + FactoryBot.create( + :case_log, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end let(:id) { case_log.id } let(:status) { case_log.status } before do - allow_any_instance_of(CaseLogsController).to receive(:authenticate_user!).and_return(true) + sign_in user end it "displays a tasklist header" do diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index 43ebcf732..65ba8abe7 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -3,12 +3,26 @@ require_relative "helpers" RSpec.describe "validations" do include Helpers - let(:case_log) { FactoryBot.create(:case_log, :in_progress) } - let(:empty_case_log) { FactoryBot.create(:case_log) } + let(:user) { FactoryBot.create(:user) } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end + let(:empty_case_log) do + FactoryBot.create( + :case_log, + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end let(:id) { case_log.id } before do - allow_any_instance_of(CaseLogsController).to receive(:authenticate_user!).and_return(true) + sign_in user end describe "Question validation" do @@ -86,7 +100,15 @@ RSpec.describe "validations" do describe "Soft Validation" do context "given a weekly net income that is above the expected amount for the given economic status but below the hard max" do - let(:case_log) { FactoryBot.create(:case_log, :in_progress, ecstat1: "Full-time - 30 hours or more") } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + ecstat1: "Full-time - 30 hours or more", + owning_organisation: user.organisation, + managing_organisation: user.organisation + ) + end let(:income_over_soft_limit) { 750 } let(:income_under_soft_limit) { 700 }