Browse Source
* Clear invalidated earnings values * Only run the earnings validation for 2023 onwardspull/2244/head
kosiakkatrina
10 months ago
committed by
GitHub
4 changed files with 143 additions and 1 deletions
@ -0,0 +1,11 @@ |
|||||||
|
desc "Clear earnings for lettings logs that fail validation" |
||||||
|
task clear_invalidated_earnings: :environment do |
||||||
|
LettingsLog.filter_by_year(2023).find_each do |lettings_log| |
||||||
|
lettings_log.validate_net_income(lettings_log) |
||||||
|
if lettings_log.errors[:earnings].present? |
||||||
|
lettings_log.earnings = nil |
||||||
|
lettings_log.incfreq = nil |
||||||
|
lettings_log.save!(validate: false) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,110 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require "rake" |
||||||
|
|
||||||
|
RSpec.describe "clear_invalidated_earnings" do |
||||||
|
describe ":clear_invalidated_earnings", type: :task do |
||||||
|
subject(:task) { Rake::Task["clear_invalidated_earnings"] } |
||||||
|
|
||||||
|
before do |
||||||
|
Rake.application.rake_require("tasks/clear_invalidated_earnings") |
||||||
|
Rake::Task.define_task(:environment) |
||||||
|
task.reenable |
||||||
|
FormHandler.instance.use_real_forms! |
||||||
|
end |
||||||
|
|
||||||
|
context "when the rake task is run" do |
||||||
|
context "and there are 2023 logs with invalid earnings" do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let!(:lettings_log) { create(:lettings_log, :completed, created_by: user, voiddate: nil, mrcdate: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
lettings_log.startdate = Time.zone.local(2023, 4, 4) |
||||||
|
lettings_log.incfreq = 1 |
||||||
|
lettings_log.earnings = 20 |
||||||
|
lettings_log.hhmemb = 1 |
||||||
|
lettings_log.ecstat1 = 1 |
||||||
|
lettings_log.save!(validate: false) |
||||||
|
end |
||||||
|
|
||||||
|
it "clears earnings" do |
||||||
|
initial_updated_at = lettings_log.updated_at |
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(20) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
lettings_log.reload |
||||||
|
|
||||||
|
expect(lettings_log.incfreq).to eq(nil) |
||||||
|
expect(lettings_log.earnings).to eq(nil) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
expect(lettings_log.updated_at).not_to eq(initial_updated_at) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and there are valid 2023 logs" do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let!(:lettings_log) { create(:lettings_log, :completed, created_by: user, voiddate: nil, mrcdate: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
lettings_log.startdate = Time.zone.local(2023, 4, 4) |
||||||
|
lettings_log.incfreq = 1 |
||||||
|
lettings_log.earnings = 95 |
||||||
|
lettings_log.hhmemb = 1 |
||||||
|
lettings_log.ecstat1 = 1 |
||||||
|
lettings_log.save! |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the logs" do |
||||||
|
initial_updated_at = lettings_log.updated_at |
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(95) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
lettings_log.reload |
||||||
|
|
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(95) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
expect(lettings_log.updated_at).to eq(initial_updated_at) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and there are 2022 logs" do |
||||||
|
let(:user) { create(:user) } |
||||||
|
let!(:lettings_log) { create(:lettings_log, :completed, created_by: user, voiddate: nil, mrcdate: nil) } |
||||||
|
|
||||||
|
before do |
||||||
|
lettings_log.startdate = Time.zone.local(2022, 4, 4) |
||||||
|
lettings_log.incfreq = 1 |
||||||
|
lettings_log.earnings = 20 |
||||||
|
lettings_log.hhmemb = 1 |
||||||
|
lettings_log.ecstat1 = 1 |
||||||
|
lettings_log.save!(validate: false) |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the logs" do |
||||||
|
initial_updated_at = lettings_log.updated_at |
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(20) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
lettings_log.reload |
||||||
|
|
||||||
|
expect(lettings_log.incfreq).to eq(1) |
||||||
|
expect(lettings_log.earnings).to eq(20) |
||||||
|
expect(lettings_log.hhmemb).to eq(1) |
||||||
|
expect(lettings_log.ecstat1).to eq(1) |
||||||
|
expect(lettings_log.updated_at).to eq(initial_updated_at) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue