Browse Source

Make use of :ignore-validation-errors trait

pull/2493/head
Rachael Booth 6 months ago
parent
commit
b6e02eefd5
  1. 1
      spec/factories/lettings_log.rb
  2. 15
      spec/requests/start_controller_spec.rb

1
spec/factories/lettings_log.rb

@ -216,6 +216,7 @@ FactoryBot.define do
trait :ignore_validation_errors do trait :ignore_validation_errors do
to_create do |instance| to_create do |instance|
instance.valid? instance.valid?
instance.errors.clear
instance.save!(validate: false) instance.save!(validate: false)
end end
end end

15
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 it "shows the correct counts of logs created by them" do
last_year_in_progress_count = 2 last_year_in_progress_count = 2
this_year_in_progress_count = 3 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) create_list(:lettings_log, last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year)
old_logs.each { |log| log.save!(validate: false) }
create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today) create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today)
get root_path get root_path
@ -218,8 +217,7 @@ RSpec.describe StartController, type: :request do
end end
it "does not include logs created by other users in the count, whether in their organisation or not" do 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) create(:lettings_log, :in_progress, :ignore_validation_errors, assigned_to: coordinator, startdate: Time.zone.today - 1.year)
old_log.save!(validate: false)
create(:lettings_log, :in_progress, assigned_to: provider_2, startdate: Time.zone.today) create(:lettings_log, :in_progress, assigned_to: provider_2, startdate: Time.zone.today)
get root_path 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 it "shows the correct counts of logs created by all users in their organisation" do
last_year_in_progress_count = 2 last_year_in_progress_count = 2
this_year_in_progress_count = 3 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) create_list(:lettings_log, last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year)
old_logs.each { |log| log.save!(validate: false) }
create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today) create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today)
get root_path get root_path
@ -291,11 +288,9 @@ RSpec.describe StartController, type: :request do
coordinator_lettings_this_year_in_progress_count = 3 coordinator_lettings_this_year_in_progress_count = 3
provider_2_lettings_last_year_in_progress_count = 2 provider_2_lettings_last_year_in_progress_count = 2
provider_2_sales_this_year_in_progress_count = 3 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) 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)
old_logs.each { |log| log.save!(validate: false) }
create_list(:lettings_log, coordinator_lettings_this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today) 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) 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)
old_logs.each { |log| log.save!(validate: false) }
create_list(:sales_log, provider_2_sales_this_year_in_progress_count, :in_progress, assigned_to: provider_2, saledate: Time.zone.today) 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 get root_path

Loading…
Cancel
Save