Browse Source

Infer Incref (#1823)

pull/1827/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
4693ed58b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/models/derived_variables/lettings_log_variables.rb
  2. 6
      lib/tasks/correct_incref_values.rake
  3. 36
      spec/lib/tasks/correct_incref_values_spec.rb
  4. 9
      spec/models/lettings_log_spec.rb

16
app/models/derived_variables/lettings_log_variables.rb

@ -128,6 +128,22 @@ private
incref: 1, incref: 1,
}, },
}, },
{
conditions: {
net_income_known: 0,
},
derived_values: {
incref: 0,
},
},
{
conditions: {
net_income_known: 1,
},
derived_values: {
incref: 2,
},
},
].freeze ].freeze
def clear_inapplicable_derived_values! def clear_inapplicable_derived_values!

6
lib/tasks/correct_incref_values.rake

@ -0,0 +1,6 @@
desc "Alter incref values for non imported lettings logs in the database"
task correct_incref_values: :environment do
LettingsLog.where(old_id: nil, net_income_known: 0).update!(incref: 0)
LettingsLog.where(old_id: nil, net_income_known: 1).update!(incref: 2)
LettingsLog.where(old_id: nil, net_income_known: 2).update!(incref: 1)
end

36
spec/lib/tasks/correct_incref_values_spec.rb

@ -0,0 +1,36 @@
require "rails_helper"
require "rake"
RSpec.describe "correct_incref_values" do
describe ":correct_incref_values", type: :task do
subject(:task) { Rake::Task["correct_incref_values"] }
before do
Rake.application.rake_require("tasks/correct_incref_values")
Rake::Task.define_task(:environment)
task.reenable
end
context "when the rake task is run" do
let!(:lettings_log) { create(:lettings_log, :completed) }
it "updates lettings logs with net_income_known 0 (yes) to have incref 0 (no)" do
lettings_log.update!(net_income_known: 0, incref: nil)
task.invoke
expect(lettings_log.reload.incref).to eq(0)
end
it "updates lettings logs with net_income_known 1 (no) to have incref 2 (don't know)" do
lettings_log.update!(net_income_known: 1, incref: nil)
task.invoke
expect(lettings_log.reload.incref).to eq(2)
end
it "updates lettings logs with net_income_known 2 (prefers not to say) to have incref 1 (yes)" do
lettings_log.update!(net_income_known: 2, incref: nil)
task.invoke
expect(lettings_log.reload.incref).to eq(1)
end
end
end
end

9
spec/models/lettings_log_spec.rb

@ -248,8 +248,13 @@ RSpec.describe LettingsLog do
end end
it "correctly derives and saves incref" do it "correctly derives and saves incref" do
record_from_db = described_class.find(lettings_log.id) expect(lettings_log.reload.incref).to eq(1)
expect(record_from_db["incref"]).to eq(1)
lettings_log.update!(net_income_known: 1)
expect(lettings_log.reload.incref).to eq(2)
lettings_log.update!(net_income_known: 0)
expect(lettings_log.reload.incref).to eq(0)
end end
it "correctly derives and saves renttype" do it "correctly derives and saves renttype" do

Loading…
Cancel
Save