diff --git a/spec/lib/tasks/dupicate_rent_periods_spec.rb b/spec/lib/tasks/dupicate_rent_periods_spec.rb index 6476b7b2b..d3bbe1013 100644 --- a/spec/lib/tasks/dupicate_rent_periods_spec.rb +++ b/spec/lib/tasks/dupicate_rent_periods_spec.rb @@ -6,12 +6,11 @@ RSpec.describe "duplicate_rent_periods" do Rake.application.rake_require("tasks/duplicate_rent_periods") Rake::Task.define_task(:environment) allow(Rails.logger).to receive(:info) - organisation = create(:organisation, rent_periods: (1..11).to_a) + organisation = create(:organisation, rent_periods: (2..11).to_a) - [2, 4, 6, 11].each do |rent_period| - org_rent_period = build(:organisation_rent_period, organisation:) + [2, 4, 6, 11, 2, 11, 11].each do |rent_period| + org_rent_period = build(:organisation_rent_period, organisation:, rent_period:) org_rent_period.save!(validate: false) - org_rent_period.update_column(:rent_period, rent_period) end end @@ -25,9 +24,9 @@ RSpec.describe "duplicate_rent_periods" do it "logs the correct information about duplicate rent periods" do task.invoke - expect(Rails.logger).to have_received(:info).with(include("Total number of records: 15")) - expect(Rails.logger).to have_received(:info).with(include("Number of affected records: 8")) - expect(Rails.logger).to have_received(:info).with(include("Number of records to delete: 4")) + expect(Rails.logger).to have_received(:info).with(include("Total number of records: 17")) + expect(Rails.logger).to have_received(:info).with(include("Number of affected records: 11")) + expect(Rails.logger).to have_received(:info).with(include("Number of records to delete: 7")) expect(Rails.logger).to have_received(:info).with(include("Number of records to keep: 4")) end end @@ -40,8 +39,11 @@ RSpec.describe "duplicate_rent_periods" do end it "deletes redundant rent periods" do - expect { task.invoke }.to change(OrganisationRentPeriod, :count).by(-4) - expect(Rails.logger).to have_received(:info).with(include("Number of deleted duplicate records: 4")) + expect { task.invoke }.to change(OrganisationRentPeriod, :count).by(-7) + expect(Rails.logger).to have_received(:info).with(include("Number of deleted duplicate records: 7")) + + remaining_rent_periods = OrganisationRentPeriod.pluck(:rent_period) + expect(remaining_rent_periods).to match_array((2..11).to_a) end end end