From b6e02eefd56193cdd60d40da9a4dc88a4c94866b Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Fri, 12 Jul 2024 16:20:16 +0100 Subject: [PATCH] Make use of :ignore-validation-errors trait --- spec/factories/lettings_log.rb | 1 + spec/requests/start_controller_spec.rb | 15 +++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/spec/factories/lettings_log.rb b/spec/factories/lettings_log.rb index 62f0cb514..8ebe44875 100644 --- a/spec/factories/lettings_log.rb +++ b/spec/factories/lettings_log.rb @@ -216,6 +216,7 @@ FactoryBot.define do trait :ignore_validation_errors do to_create do |instance| instance.valid? + instance.errors.clear instance.save!(validate: false) end end diff --git a/spec/requests/start_controller_spec.rb b/spec/requests/start_controller_spec.rb index ee0fd101e..699bdfa9c 100644 --- a/spec/requests/start_controller_spec.rb +++ b/spec/requests/start_controller_spec.rb @@ -203,8 +203,7 @@ RSpec.describe StartController, type: :request do it "shows the correct counts of logs created by them" do last_year_in_progress_count = 2 this_year_in_progress_count = 3 - old_logs = build_list(:lettings_log, last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) - old_logs.each { |log| log.save!(validate: false) } + create_list(:lettings_log, last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today) get root_path @@ -218,8 +217,7 @@ RSpec.describe StartController, type: :request do end it "does not include logs created by other users in the count, whether in their organisation or not" do - old_log = build(:lettings_log, :in_progress, assigned_to: coordinator, startdate: Time.zone.today - 1.year) - old_log.save!(validate: false) + create(:lettings_log, :in_progress, :ignore_validation_errors, assigned_to: coordinator, startdate: Time.zone.today - 1.year) create(:lettings_log, :in_progress, assigned_to: provider_2, startdate: Time.zone.today) get root_path @@ -239,8 +237,7 @@ RSpec.describe StartController, type: :request do it "shows the correct counts of logs created by all users in their organisation" do last_year_in_progress_count = 2 this_year_in_progress_count = 3 - old_logs = build_list(:lettings_log, last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) - old_logs.each { |log| log.save!(validate: false) } + create_list(:lettings_log, last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today) get root_path @@ -291,11 +288,9 @@ RSpec.describe StartController, type: :request do coordinator_lettings_this_year_in_progress_count = 3 provider_2_lettings_last_year_in_progress_count = 2 provider_2_sales_this_year_in_progress_count = 3 - old_logs = build_list(:lettings_log, provider_1_lettings_last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) - old_logs.each { |log| log.save!(validate: false) } + create_list(:lettings_log, provider_1_lettings_last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, coordinator_lettings_this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today) - old_logs = build_list(:lettings_log, provider_2_lettings_last_year_in_progress_count, :in_progress, assigned_to: provider_2, startdate: Time.zone.today - 1.year) - old_logs.each { |log| log.save!(validate: false) } + create_list(:lettings_log, provider_2_lettings_last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_2, startdate: Time.zone.today - 1.year) create_list(:sales_log, provider_2_sales_this_year_in_progress_count, :in_progress, assigned_to: provider_2, saledate: Time.zone.today) get root_path