From 5606d0649143befee94a1537c4038d08df4298fb Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Fri, 17 Mar 2023 14:41:00 +0000 Subject: [PATCH] CLDC-1917 test flakiness fix (#1437) * feat: add validation with feature flag, typo fix and update tests * feat: flip feature toggle * feat: update feature toggle name * feat: fix form handler inequality * refactor: linting * refactor: use between in form handler * feat: remove feature toggle * feat: add dynamic date to lettings log factory * feat: fix log_summary_component_spec.rb tests * feat: update lettings_log.rb and start fixing lettings_log_spec.rb * feat: fix more tests * feat: fix more tests * feat: fix lettings log import service * refactor: linting * feat: fix checkboxes_spec.rb * feat: fix interruption_screen_helper_spec.rb * feat: fix check_answers_helper_spec.rb * feat: fix page_routing_spec.rb * feat: fix lettings_logs_field_import_service_spec.rb * feat: fix lettings_log_spec.rb * feat: fix question_spec.rb * feat: fix lettings_logs_controller_spec.rb * feat: fix check_answers_page_lettings_logs_spec.rb * feat: fix tenancy_validations_spec.rb * feat: fix validations_spec.rb * feat: fix accessible_autocomplete_spec.rb * feat: fix form_navigation_spec.rb * feat: fix soft_validations_spec.rb * feat: fix lettings_log_export_service_spec.rb * feat: fix saving_data_spec.rb * feat: fix page_spec.rb * feat: fix form_controller_spec.rb * refactor: linting * feat: fix subsection_spec.rb * feat: fix lettings_log_spec.rb * feat: fix financial_validations_spec.rb * feat: fix tasklist_page_spec.rb * feat: fix conditional_questions_spec.rb * feat: fix form_page_error_helper_spec.rb and log_summary_component_spec.rb * feat: fix lettings_log_csv_service_spec.rb * feat: fix tasklist_helper_spec.rb * refactor: linting * refactor: linting * feat: fix lettings_log_spec.rb * refactor: linting * refactor: replace financial year with collection yaer * feat: respond to PR comments pt. 1 * feat: respond to PR comments pt. 2 * feat: unfreeze all timecop freezes --- spec/helpers/collection_time_helper_spec.rb | 1 + spec/models/form_handler_spec.rb | 1 + spec/models/validations/sales/financial_validations_spec.rb | 2 +- spec/models/validations/tenancy_validations_spec.rb | 4 ++++ spec/requests/lettings_logs_controller_spec.rb | 2 +- spec/requests/sales_logs_controller_spec.rb | 2 +- .../services/bulk_upload/lettings/year2022/row_parser_spec.rb | 1 + .../services/bulk_upload/lettings/year2023/row_parser_spec.rb | 1 + 8 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spec/helpers/collection_time_helper_spec.rb b/spec/helpers/collection_time_helper_spec.rb index 0c187020e..43a14025e 100644 --- a/spec/helpers/collection_time_helper_spec.rb +++ b/spec/helpers/collection_time_helper_spec.rb @@ -9,6 +9,7 @@ RSpec.describe CollectionTimeHelper do Timecop.freeze(now) do example.run end + Timecop.return end context "when the date is after 1st of April" do diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index a6b5b181a..417da6639 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -9,6 +9,7 @@ RSpec.describe FormHandler do Singleton.__init__(described_class) example.run end + Timecop.return Singleton.__init__(described_class) end diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index 350cc66ef..093c491a4 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -274,7 +274,7 @@ RSpec.describe Validations::Sales::FinancialValidations do Timecop.freeze(now) do example.run end - Timecop.unfreeze + Timecop.return end context "with a log in the 22/23 collection year" do diff --git a/spec/models/validations/tenancy_validations_spec.rb b/spec/models/validations/tenancy_validations_spec.rb index 8f7d79e29..9f3a2b873 100644 --- a/spec/models/validations/tenancy_validations_spec.rb +++ b/spec/models/validations/tenancy_validations_spec.rb @@ -7,6 +7,10 @@ RSpec.describe Validations::TenancyValidations do Timecop.freeze(Time.zone.local(2021, 5, 1)) end + after do + Timecop.unfreeze + end + let(:validator_class) { Class.new { include Validations::TenancyValidations } } let(:record) { FactoryBot.create(:lettings_log, startdate: Time.zone.local(2021, 5, 1), needstype: 1, rent_type: 1) } diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index c5ee2a6ab..066cd1f35 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -337,7 +337,7 @@ RSpec.describe LettingsLogsController, type: :request do Timecop.freeze(2022, 3, 1) do example.run end - Timecop.unfreeze + Timecop.return end let!(:lettings_log_2021) do diff --git a/spec/requests/sales_logs_controller_spec.rb b/spec/requests/sales_logs_controller_spec.rb index 1d68b045b..0a7ca0790 100644 --- a/spec/requests/sales_logs_controller_spec.rb +++ b/spec/requests/sales_logs_controller_spec.rb @@ -235,7 +235,7 @@ RSpec.describe SalesLogsController, type: :request do Timecop.freeze(2022, 12, 1) do example.run end - Timecop.unfreeze + Timecop.return end let!(:sales_log_2022) do diff --git a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb index 312a63a3b..f03ea894b 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -610,6 +610,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do Timecop.freeze(Date.new(2022, 4, 2)) do example.run end + Timecop.return end let(:attributes) { { bulk_upload:, field_96: "1", field_97: "1", field_98: "22" } } diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index f658f7b04..80df8f54f 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -562,6 +562,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do Timecop.freeze(Date.new(2022, 4, 2)) do example.run end + Timecop.return end let(:attributes) { { bulk_upload:, field_7: "1", field_8: "1", field_9: "22" } }