diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 94347c6f1..9212b6e76 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -43,17 +43,14 @@ FactoryBot.define do purchid { rand(999_999_999).to_s } end trait :duplicate do + shared_ownership_setup_complete purchid { "PC123" } - ownershipsch { 2 } - type { 8 } - jointpur { 2 } saledate { Time.zone.today } age1_known { 1 } age1 { 20 } sex1 { "F" } ecstat1 { 1 } postcode_full { "A1 1AA" } - privacynotice { 1 } uprn_known { 0 } end trait :completed do diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index baa26ca44..6d63ebbc1 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -1,23 +1,27 @@ require "rails_helper" RSpec.describe CheckAnswersHelper do - let(:form) { lettings_log.form } - let(:subsection) { form.get_subsection("household_characteristics") } - let(:lettings_log) { FactoryBot.build(:lettings_log, :in_progress) } + let(:lettings_log) { FactoryBot.build(:lettings_log) } let(:current_user) { FactoryBot.build(:user) } + let(:subsection) { instance_double(Form::Subsection, form: lettings_log.form) } + let(:questions) do + [ + Form::Lettings::Questions::Hhmemb, + Form::Lettings::Questions::Age1Known, + Form::Lettings::Questions::Age1, + Form::Lettings::Questions::GenderIdentity1, + ].map { |q| q.new(nil, nil, instance_double(Form::Page, subsection:, routed_to?: true)) } + end - around do |example| - Timecop.freeze(Time.zone.local(2022, 1, 1)) do - Singleton.__init__(FormHandler) - example.run - end + before do + allow(subsection).to receive(:applicable_questions).and_return(questions) end describe "display_answered_questions_summary" do context "when a section hasn't been completed yet" do it "returns that you have unanswered questions" do expect(display_answered_questions_summary(subsection, lettings_log, current_user)) - .to match(/You have answered 4 of 10 questions./) + .to match(/You have answered 0 of 4 questions./) end end @@ -25,9 +29,8 @@ RSpec.describe CheckAnswersHelper do it "returns that you have answered all the questions" do lettings_log.sex1 = "F" lettings_log.hhmemb = 1 - lettings_log.propcode = "123" - lettings_log.ecstat1 = 200 - lettings_log.ecstat2 = 9 + lettings_log.age1_known = 1 + lettings_log.age1 = 18 expect(display_answered_questions_summary(subsection, lettings_log, current_user)) .to match(/You answered all the questions./) expect(display_answered_questions_summary(subsection, lettings_log, current_user)) diff --git a/spec/helpers/collection_time_helper_spec.rb b/spec/helpers/collection_time_helper_spec.rb index 859431c57..e659706de 100644 --- a/spec/helpers/collection_time_helper_spec.rb +++ b/spec/helpers/collection_time_helper_spec.rb @@ -5,11 +5,8 @@ RSpec.describe CollectionTimeHelper do let(:user) { create(:user, :data_coordinator) } describe "Current collection start year" do - around do |example| - Timecop.freeze(now) do - example.run - end - Timecop.return + before do + allow(Time).to receive(:now).and_return(now) end context "when the date is after 1st of April" do diff --git a/spec/helpers/duplicate_logs_helper_spec.rb b/spec/helpers/duplicate_logs_helper_spec.rb index fbc5355ed..ed4397ee1 100644 --- a/spec/helpers/duplicate_logs_helper_spec.rb +++ b/spec/helpers/duplicate_logs_helper_spec.rb @@ -1,16 +1,6 @@ require "rails_helper" RSpec.describe DuplicateLogsHelper do - before do - Timecop.freeze(Time.zone.local(2024, 3, 1)) - Singleton.__init__(FormHandler) - end - - after do - Timecop.return - Singleton.__init__(FormHandler) - end - describe "#duplicates_for_user" do let(:org) { create(:organisation) } let(:other_org) { create(:organisation) } diff --git a/spec/helpers/filters_helper_spec.rb b/spec/helpers/filters_helper_spec.rb index 52a9595fc..fb7bda18e 100644 --- a/spec/helpers/filters_helper_spec.rb +++ b/spec/helpers/filters_helper_spec.rb @@ -241,11 +241,8 @@ RSpec.describe FiltersHelper do describe "#collection_year_options" do context "with 23/24 as the current collection year" do - around do |example| - Timecop.freeze(Time.zone.local(2023, 5, 1)) do - example.run - end - Timecop.return + before do + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) end it "has the correct options" do @@ -258,11 +255,8 @@ RSpec.describe FiltersHelper do end context "with 24/25 as the current collection year" do - around do |example| - Timecop.freeze(Time.zone.local(2024, 5, 1)) do - example.run - end - Timecop.return + before do + allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1)) end it "has the correct options" do diff --git a/spec/helpers/form_page_error_helper_spec.rb b/spec/helpers/form_page_error_helper_spec.rb index ae9d22494..5f86e1648 100644 --- a/spec/helpers/form_page_error_helper_spec.rb +++ b/spec/helpers/form_page_error_helper_spec.rb @@ -3,15 +3,6 @@ require "rails_helper" RSpec.describe FormPageErrorHelper do describe "#remove_other_page_errors" do context "when non base other questions are removed" do - around do |example| - Timecop.freeze(Time.zone.local(2022, 1, 1)) do - Singleton.__init__(FormHandler) - example.run - end - Timecop.return - Singleton.__init__(FormHandler) - end - let!(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress) } let!(:form) { lettings_log.form } @@ -22,7 +13,7 @@ RSpec.describe FormPageErrorHelper do end it "returns details and user tabs" do - page = form.get_page("rent") + page = form.get_question("period", lettings_log).page remove_other_page_errors(lettings_log, page) expect(lettings_log.errors.count).to eq(2) expect(lettings_log.errors.map(&:attribute)).to include(:period) diff --git a/spec/helpers/interruption_screen_helper_spec.rb b/spec/helpers/interruption_screen_helper_spec.rb index e4f64e2bb..f364299cf 100644 --- a/spec/helpers/interruption_screen_helper_spec.rb +++ b/spec/helpers/interruption_screen_helper_spec.rb @@ -1,9 +1,6 @@ require "rails_helper" RSpec.describe InterruptionScreenHelper do - form_handler = FormHandler.instance - let(:form) { form_handler.get_form("test_form") } - let(:subsection) { form.get_subsection("household_characteristics") } let(:user) { create(:user) } let(:lettings_log) do create( @@ -11,7 +8,9 @@ RSpec.describe InterruptionScreenHelper do :in_progress, hhmemb: 1, ecstat1: 1, + period: 1, earnings: 750, + net_income_known: 0, incfreq: 1, assigned_to: user, sex1: "F", @@ -19,15 +18,6 @@ RSpec.describe InterruptionScreenHelper do ) end - around do |example| - Timecop.freeze(Time.zone.local(2022, 1, 1)) do - Singleton.__init__(FormHandler) - example.run - end - Timecop.return - Singleton.__init__(FormHandler) - end - describe "display_informative_text" do context "when 2 out of 2 arguments are given" do it "returns correct informative text" do @@ -249,7 +239,7 @@ RSpec.describe InterruptionScreenHelper do it "returns a list of questions affected by the soft validation" do expect(soft_validation_affected_questions(question, lettings_log).count).to eq(2) - expect(soft_validation_affected_questions(question, lettings_log).map(&:id)).to eq(%w[age1 ecstat1]) + expect(soft_validation_affected_questions(question, lettings_log).map(&:id)).to eq(%w[ecstat1 age1]) end end end diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index fec1ce53b..211e6e9cf 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -51,7 +51,7 @@ RSpec.describe LocationsHelper do let(:location) { FactoryBot.create(:location, startdate: nil) } before do - Timecop.freeze(2023, 10, 10) + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 10, 10)) allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true) end @@ -228,7 +228,7 @@ RSpec.describe LocationsHelper do context "with previous deactivations" do context "and all reactivated deactivations" do before do - Timecop.freeze(Time.zone.local(2023, 11, 10)) + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), location:) Timecop.return @@ -244,7 +244,7 @@ RSpec.describe LocationsHelper do context "and non reactivated deactivation" do before do - Timecop.freeze(Time.zone.local(2023, 11, 10)) + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, location:) Timecop.return @@ -262,7 +262,7 @@ RSpec.describe LocationsHelper do context "with out of order deactivations" do context "and all reactivated deactivations" do before do - Timecop.freeze(Time.zone.local(2023, 11, 10)) + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), location:) Timecop.return @@ -278,7 +278,7 @@ RSpec.describe LocationsHelper do context "and one non reactivated deactivation" do before do - Timecop.freeze(Time.zone.local(2023, 11, 10)) + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:) Timecop.return @@ -296,7 +296,7 @@ RSpec.describe LocationsHelper do context "with multiple out of order deactivations" do context "and one non reactivated deactivation" do before do - Timecop.freeze(Time.zone.local(2023, 11, 10)) + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:) @@ -314,7 +314,7 @@ RSpec.describe LocationsHelper do context "with intersecting deactivations" do before do - Timecop.freeze(Time.zone.local(2023, 11, 10)) + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), location:) Timecop.return diff --git a/spec/helpers/schemes_helper_spec.rb b/spec/helpers/schemes_helper_spec.rb index 3d1010d4a..0df032c3f 100644 --- a/spec/helpers/schemes_helper_spec.rb +++ b/spec/helpers/schemes_helper_spec.rb @@ -5,11 +5,7 @@ RSpec.describe SchemesHelper do let(:scheme) { FactoryBot.create(:scheme, created_at: Time.zone.today) } before do - Timecop.freeze(2023, 1, 10) - end - - after do - Timecop.unfreeze + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 1, 10)) end it "returns one active period without to date" do diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 7b16a2507..26bcb0b3b 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -1,14 +1,10 @@ require "rails_helper" RSpec.describe TasklistHelper do - let(:now) { Time.utc(2022, 1, 1) } + let(:now) { Time.utc(2025, 1, 1) } - around do |example| - Timecop.freeze(now) do - Singleton.__init__(FormHandler) - example.run - end - Timecop.return + before do + allow(Time).to receive(:now).and_return(now) end describe "with lettings" do @@ -17,12 +13,12 @@ RSpec.describe TasklistHelper do describe "get next incomplete section" do it "returns the first subsection name if it is not completed" do - expect(get_next_incomplete_section(lettings_log).id).to eq("household_characteristics") + expect(get_next_incomplete_section(lettings_log).id).to eq("property_information") end it "returns the first subsection name if it is partially completed" do - lettings_log["tenancycode"] = 123 - expect(get_next_incomplete_section(lettings_log).id).to eq("household_characteristics") + lettings_log["uprn_known"] = 0 + expect(get_next_incomplete_section(lettings_log).id).to eq("property_information") end end @@ -82,8 +78,9 @@ RSpec.describe TasklistHelper do end describe "with sales" do + let(:now) { Time.utc(2022, 4, 4) } let(:empty_sales_log) { create(:sales_log, owning_organisation: nil) } - let(:completed_sales_log) { create(:sales_log, :completed) } + let(:completed_sales_log) { create(:sales_log, :completed, saledate: now) } describe "get sections count" do context "with an empty sales log" do @@ -126,13 +123,11 @@ RSpec.describe TasklistHelper do end context "when collection_period_open? == false" do - let(:now) { Time.utc(2022, 6, 1) } - let!(:sales_log) { create(:sales_log, :completed, saledate: now) } + let(:now) { Time.utc(2024, 6, 1) } + let!(:sales_log) { build(:sales_log, :completed, saledate: Time.utc(2022, 6, 1)) } it "returns relevant text" do - Timecop.freeze(now + 1.year) do - expect(review_log_text(sales_log)).to eq("This log is from the 2022/2023 collection window, which is now closed.") - end + expect(review_log_text(sales_log)).to eq("This log is from the 2022/2023 collection window, which is now closed.") end end @@ -148,37 +143,26 @@ RSpec.describe TasklistHelper do context "with lettings log" do context "when collection_period_open? == true" do - context "with 2023 deadline" do - let(:now) { Time.utc(2022, 6, 1) } - let(:lettings_log) { create(:lettings_log, :completed) } + let(:now) { Time.utc(2022, 6, 1) } + let(:lettings_log) { build(:lettings_log, :completed, startdate: now, id: 123) } - it "returns relevant text" do - expect(review_log_text(lettings_log)).to eq( - "You can #{govuk_link_to 'review and make changes to this log', review_lettings_log_path(lettings_log)} until 9 June 2023.".html_safe, - ) - end + before do + allow(lettings_log.form).to receive(:submission_deadline).and_return(Time.utc(2023, 6, 9)) end - context "with 2024 deadline" do - let(:now) { Time.utc(2023, 6, 20) } - let(:lettings_log) { create(:lettings_log, :completed, national: 18, waityear: 2) } - - it "returns relevant text" do - expect(review_log_text(lettings_log)).to eq( - "You can #{govuk_link_to 'review and make changes to this log', review_lettings_log_path(lettings_log)} until 7 June 2024.".html_safe, - ) - end + it "returns relevant text" do + expect(review_log_text(lettings_log)).to eq( + "You can #{govuk_link_to 'review and make changes to this log', review_lettings_log_path(lettings_log)} until 9 June 2023.".html_safe, + ) end end context "when collection_period_open? == false" do - let(:now) { Time.utc(2022, 6, 1) } - let!(:sales_log) { create(:lettings_log, :completed) } + let(:now) { Time.utc(2024, 6, 1) } + let!(:sales_log) { build(:lettings_log, :completed, startdate: Time.utc(2022, 6, 1), id: 123) } it "returns relevant text" do - Timecop.freeze(now + 1.year) do - expect(review_log_text(sales_log)).to eq("This log is from the 2022/2023 collection window, which is now closed.") - end + expect(review_log_text(sales_log)).to eq("This log is from the 2022/2023 collection window, which is now closed.") end end