kosiakkatrina
1 year ago
committed by
GitHub
4 changed files with 65 additions and 2 deletions
@ -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 |
@ -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 |
Loading…
Reference in new issue