Browse Source
* Check correct benefits value in the validation * Update some tests * Update validation * clear invalid benefits * Update more tests * Fix world * Clear the benefits * Move benefits assignpull/2868/head^2
kosiakkatrina
6 days ago
committed by
GitHub
7 changed files with 128 additions and 13 deletions
@ -0,0 +1,20 @@ |
|||||||
|
desc "clear benefit value for logs that would trigger the validation" |
||||||
|
task clear_invalid_benefits: :environment do |
||||||
|
validation_trigger_condition = "ecstat1 = 1 OR ecstat1 = 2 OR (ecstat2 = 1 AND relat2 = 'P') OR (ecstat2 = 2 AND relat2 = 'P') OR (ecstat3 = 1 AND relat3 = 'P') OR (ecstat3 = 2 AND relat3 = 'P') OR (ecstat4 = 1 AND relat4 = 'P') OR (ecstat4 = 2 AND relat4 = 'P') OR (ecstat5 = 1 AND relat5 = 'P') OR (ecstat5 = 2 AND relat5 = 'P') OR (ecstat6 = 1 AND relat6 = 'P') OR (ecstat6 = 2 AND relat6 = 'P') OR (ecstat7 = 1 AND relat7 = 'P') OR (ecstat7 = 2 AND relat7 = 'P') OR (ecstat8 = 1 AND relat8 = 'P') OR (ecstat8 = 2 AND relat8 = 'P')" |
||||||
|
LettingsLog.filter_by_year(2024).where(status: "pending", status_cache: "completed", benefits: 1).where(validation_trigger_condition).find_each do |log| |
||||||
|
log.benefits = nil |
||||||
|
log.status_cache = log.calculate_status |
||||||
|
log.skip_update_status = true |
||||||
|
|
||||||
|
unless log.save |
||||||
|
Rails.logger.info "Could not save changes to pending lettings log #{log.id}" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
LettingsLog.filter_by_year(2024).visible.where(benefits: 1).where(validation_trigger_condition).find_each do |log| |
||||||
|
log.benefits = nil |
||||||
|
unless log.save |
||||||
|
Rails.logger.info "Could not save changes to lettings log #{log.id}" |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,95 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require "rake" |
||||||
|
|
||||||
|
RSpec.describe "clear_invalid_benefits" do |
||||||
|
describe ":clear_invalid_benefits", type: :task do |
||||||
|
subject(:task) { Rake::Task["clear_invalid_benefits"] } |
||||||
|
|
||||||
|
before do |
||||||
|
Rake.application.rake_require("tasks/clear_invalid_benefits") |
||||||
|
Rake::Task.define_task(:environment) |
||||||
|
task.reenable |
||||||
|
end |
||||||
|
|
||||||
|
context "when the rake task is run" do |
||||||
|
context "and there is a completed lettings log that trips the validation" do |
||||||
|
let(:log) { build(:lettings_log, :completed, ecstat1: 1, benefits: 1, assigned_to: create(:user), period: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
log.status = "completed" |
||||||
|
log.skip_update_status = true |
||||||
|
log.save!(validate: false) |
||||||
|
end |
||||||
|
|
||||||
|
it "clear benefits and sets the log to in progress" do |
||||||
|
expect(log.reload.benefits).to eq(1) |
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
expect(log.benefits).to eq(nil) |
||||||
|
expect(log.status).to eq("in_progress") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
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", assigned_to: create(:user), period: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
log.status = "completed" |
||||||
|
log.skip_update_status = true |
||||||
|
log.save!(validate: false) |
||||||
|
end |
||||||
|
|
||||||
|
it "clear benefits and sets the log to in progress" do |
||||||
|
expect(log.reload.benefits).to eq(1) |
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
expect(log.benefits).to eq(nil) |
||||||
|
expect(log.status).to eq("in_progress") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
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", assigned_to: create(:user), period: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
log.status = "completed" |
||||||
|
log.skip_update_status = true |
||||||
|
log.save!(validate: false) |
||||||
|
end |
||||||
|
|
||||||
|
it "clear benefits and sets the log to in progress" do |
||||||
|
expect(log.reload.benefits).to eq(1) |
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
expect(log.benefits).to eq(nil) |
||||||
|
expect(log.status).to eq("in_progress") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and there is a pending lettings log that trips the validation" do |
||||||
|
let(:log) { build(:lettings_log, :completed, ecstat1: 1, benefits: 1, assigned_to: create(:user), period: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
log.status = "pending" |
||||||
|
log.status_cache = "completed" |
||||||
|
log.skip_update_status = true |
||||||
|
log.save!(validate: false) |
||||||
|
end |
||||||
|
|
||||||
|
it "clears benefits and updates the status cache" do |
||||||
|
expect(log.reload.benefits).to eq(1) |
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
expect(log.benefits).to eq(nil) |
||||||
|
expect(log.status_cache).to eq("in_progress") |
||||||
|
end |
||||||
|
|
||||||
|
it "does not change the log status" do |
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
expect(log.status).to eq("pending") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue