Browse Source

Clear the benefits

pull/2769/head
Kat 7 months ago
parent
commit
cd5be2b49e
  1. 2
      lib/tasks/clear_invalid_benefits.rake
  2. 12
      spec/lib/tasks/clear_invalid_benefits_spec.rb

2
lib/tasks/clear_invalid_benefits.rake

@ -4,6 +4,7 @@ task clear_invalid_benefits: :environment do
LettingsLog.filter_by_year(2024).where(status: "pending", status_cache: "completed", benefits: 1).where(validation_trigger_condition).find_each do |log| LettingsLog.filter_by_year(2024).where(status: "pending", status_cache: "completed", benefits: 1).where(validation_trigger_condition).find_each do |log|
log.status_cache = log.calculate_status log.status_cache = log.calculate_status
log.skip_update_status = true log.skip_update_status = true
log.benefits = nil
unless log.save unless log.save
Rails.logger.info "Could not save changes to pending lettings log #{log.id}" Rails.logger.info "Could not save changes to pending lettings log #{log.id}"
@ -11,6 +12,7 @@ task clear_invalid_benefits: :environment do
end end
LettingsLog.filter_by_year(2024).visible.where(benefits: 1).where(validation_trigger_condition).find_each do |log| LettingsLog.filter_by_year(2024).visible.where(benefits: 1).where(validation_trigger_condition).find_each do |log|
log.benefits = nil
unless log.save unless log.save
Rails.logger.info "Could not save changes to lettings log #{log.id}" Rails.logger.info "Could not save changes to lettings log #{log.id}"
end end

12
spec/lib/tasks/clear_invalid_benefits_spec.rb

@ -13,7 +13,7 @@ RSpec.describe "clear_invalid_benefits" do
context "when the rake task is run" do context "when the rake task is run" do
context "and there is a completed lettings log that trips the validation" do context "and there is a completed lettings log that trips the validation" do
let(:log) { build(:lettings_log, :completed, ecstat1: 1, benefits: 1) } let(:log) { build(:lettings_log, :completed, ecstat1: 1, benefits: 1, assigned_to: create(:user), period: nil) }
before do before do
log.status = "completed" log.status = "completed"
@ -22,6 +22,7 @@ RSpec.describe "clear_invalid_benefits" do
end end
it "clear benefits and sets the log to in progress" do it "clear benefits and sets the log to in progress" do
expect(log.reload.benefits).to eq(1)
task.invoke task.invoke
log.reload log.reload
expect(log.benefits).to eq(nil) expect(log.benefits).to eq(nil)
@ -30,7 +31,7 @@ RSpec.describe "clear_invalid_benefits" do
end end
context "and there is a lettings log that trips the validation for person 2" do context "and there is a lettings log that trips the validation for person 2" do
let(:log) { build(:lettings_log, :completed, ecstat2: 2, benefits: 1, relat2: "P") } let(:log) { build(:lettings_log, :completed, ecstat2: 2, benefits: 1, relat2: "P", assigned_to: create(:user), period: nil) }
before do before do
log.status = "completed" log.status = "completed"
@ -39,6 +40,7 @@ RSpec.describe "clear_invalid_benefits" do
end end
it "clear benefits and sets the log to in progress" do it "clear benefits and sets the log to in progress" do
expect(log.reload.benefits).to eq(1)
task.invoke task.invoke
log.reload log.reload
expect(log.benefits).to eq(nil) expect(log.benefits).to eq(nil)
@ -47,7 +49,7 @@ RSpec.describe "clear_invalid_benefits" do
end end
context "and there is a lettings log that trips the validation for person 8" do context "and there is a lettings log that trips the validation for person 8" do
let(:log) { build(:lettings_log, :completed, ecstat8: 1, benefits: 1, relat8: "P") } let(:log) { build(:lettings_log, :completed, ecstat8: 1, benefits: 1, relat8: "P", assigned_to: create(:user), period: nil) }
before do before do
log.status = "completed" log.status = "completed"
@ -56,6 +58,7 @@ RSpec.describe "clear_invalid_benefits" do
end end
it "clear benefits and sets the log to in progress" do it "clear benefits and sets the log to in progress" do
expect(log.reload.benefits).to eq(1)
task.invoke task.invoke
log.reload log.reload
expect(log.benefits).to eq(nil) expect(log.benefits).to eq(nil)
@ -64,7 +67,7 @@ RSpec.describe "clear_invalid_benefits" do
end end
context "and there is a pending lettings log that trips the validation" do context "and there is a pending lettings log that trips the validation" do
let(:log) { build(:lettings_log, :completed, ecstat1: 1, benefits: 1) } let(:log) { build(:lettings_log, :completed, ecstat1: 1, benefits: 1, assigned_to: create(:user), period: nil) }
before do before do
log.status = "pending" log.status = "pending"
@ -74,6 +77,7 @@ RSpec.describe "clear_invalid_benefits" do
end end
it "clears benefits and updates the status cache" do it "clears benefits and updates the status cache" do
expect(log.reload.benefits).to eq(1)
task.invoke task.invoke
log.reload log.reload
expect(log.benefits).to eq(nil) expect(log.benefits).to eq(nil)

Loading…
Cancel
Save