Browse Source
* further fixes * Fix date / crossover issues * Try changing form end dates * Revert "Try changing form end dates" This reverts commitpull/2505/heade027e29cf0
. * Make use of :ignore-validation-errors trait * Try with end dates in past * Revert "Try with end dates in past" This reverts commit6b87938d70
. --------- Co-authored-by: Rachael Booth <rachael.booth@softwire.com>
Arthur Campbell
6 months ago
committed by
GitHub
8 changed files with 61 additions and 164 deletions
@ -1,25 +0,0 @@
|
||||
desc "Infer nil letting allocation values as no" |
||||
task fix_nil_letting_allocation_values: :environment do |
||||
LettingsLog.where(cbl: nil) |
||||
.or(LettingsLog.where(chr: nil)) |
||||
.or(LettingsLog.where(cap: nil)) |
||||
.or(LettingsLog.filter_by_year(2024).where(accessible_register: nil)) |
||||
.find_each do |log| |
||||
next unless log.cbl.present? || log.chr.present? || log.cap.present? || log.accessible_register.present? || log.letting_allocation_unknown.present? |
||||
|
||||
log.cbl = 0 if log.cbl.blank? |
||||
log.chr = 0 if log.chr.blank? |
||||
log.cap = 0 if log.cap.blank? |
||||
log.accessible_register = 0 if log.form.start_year_after_2024? && log.accessible_register.blank? |
||||
|
||||
log.letting_allocation_unknown = if log.cbl == 1 || log.chr == 1 || log.cap == 1 || log.accessible_register == 1 |
||||
0 |
||||
else |
||||
1 |
||||
end |
||||
|
||||
next if log.save |
||||
|
||||
Rails.logger.info("NilLettingsAllocationValues: Unable to save changes to log #{log.id}") |
||||
end |
||||
end |
@ -1,73 +0,0 @@
|
||||
require "rails_helper" |
||||
require "rake" |
||||
|
||||
RSpec.describe "fix_nil_letting_allocation_values" do |
||||
describe ":fix_nil_letting_allocation_values", type: :task do |
||||
subject(:task) { Rake::Task["fix_nil_letting_allocation_values"] } |
||||
|
||||
before do |
||||
Rake.application.rake_require("tasks/fix_nil_letting_allocation_values") |
||||
Rake::Task.define_task(:environment) |
||||
task.reenable |
||||
end |
||||
|
||||
it "sets nil values to 0 when one allocation type value is non-nil" do |
||||
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: nil, chr: nil, cap: 1, accessible_register: nil, letting_allocation_unknown: nil) |
||||
|
||||
task.invoke |
||||
|
||||
log.reload |
||||
expect(log.cbl).to be 0 |
||||
expect(log.chr).to be 0 |
||||
expect(log.cap).to be 1 |
||||
expect(log.accessible_register).to be 0 |
||||
expect(log.letting_allocation_unknown).to be 0 |
||||
end |
||||
|
||||
it "sets nil values to 0 and letting_allocation_unknown to 1 when non-nil allocation type values are 0" do |
||||
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: 0, chr: 0, cap: nil, accessible_register: nil, letting_allocation_unknown: nil) |
||||
|
||||
task.invoke |
||||
|
||||
log.reload |
||||
expect(log.cbl).to be 0 |
||||
expect(log.chr).to be 0 |
||||
expect(log.cap).to be 0 |
||||
expect(log.accessible_register).to be 0 |
||||
expect(log.letting_allocation_unknown).to be 1 |
||||
end |
||||
|
||||
it "does not set anything when question has not been answered at all" do |
||||
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: nil, chr: nil, cap: nil, accessible_register: nil, letting_allocation_unknown: nil) |
||||
|
||||
task.invoke |
||||
|
||||
log.reload |
||||
expect(log.cbl).to be_nil |
||||
expect(log.chr).to be_nil |
||||
expect(log.cap).to be_nil |
||||
expect(log.accessible_register).to be_nil |
||||
expect(log.letting_allocation_unknown).to be_nil |
||||
end |
||||
|
||||
it "does not set accessible_register for logs before 2024" do |
||||
log = create(:lettings_log, :setup_completed, startdate: Time.zone.local(2023, 5, 1), cbl: 1, chr: nil, cap: nil, accessible_register: nil, letting_allocation_unknown: nil) |
||||
|
||||
task.invoke |
||||
|
||||
log.reload |
||||
expect(log.cbl).to be 1 |
||||
expect(log.chr).to be 0 |
||||
expect(log.cap).to be 0 |
||||
expect(log.accessible_register).to be_nil |
||||
expect(log.letting_allocation_unknown).to be 0 |
||||
end |
||||
|
||||
it "logs the log id if the change cannot be saved" do |
||||
log = create(:lettings_log, :ignore_validation_errors, :setup_completed, startdate: Time.zone.local(2022, 4, 1), cbl: 1, chr: nil, cap: nil, letting_allocation_unknown: nil) |
||||
|
||||
expect(Rails.logger).to receive(:info).with(match(/log #{log.id}/)) |
||||
task.invoke |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue