Browse Source

CLDC-2748 Update min value for age (#1918)

* Update min value for age

* Update existing 0 age values to 1
pull/1919/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
16d2836d08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      config/forms/2021_2022.json
  2. 10
      lib/tasks/correct_min_age_values.rake
  3. 80
      spec/lib/tasks/correct_min_age_values_spec.rb

14
config/forms/2021_2022.json

@ -2076,7 +2076,7 @@
"check_answer_label": "Person 2’s age",
"check_answers_card_number": 2,
"type": "numeric",
"min": 0,
"min": 1,
"max": 120,
"step": 1,
"width": 2,
@ -2611,7 +2611,7 @@
"check_answer_label": "Person 3’s age",
"check_answers_card_number": 3,
"type": "numeric",
"min": 0,
"min": 1,
"max": 120,
"step": 1,
"width": 2,
@ -3143,7 +3143,7 @@
"check_answer_label": "Person 4’s age",
"check_answers_card_number": 4,
"type": "numeric",
"min": 0,
"min": 1,
"max": 120,
"step": 1,
"width": 2,
@ -3672,7 +3672,7 @@
"check_answer_label": "Person 5’s age",
"check_answers_card_number": 5,
"type": "numeric",
"min": 0,
"min": 1,
"max": 120,
"step": 1,
"width": 2,
@ -4198,7 +4198,7 @@
"check_answer_label": "Person 6’s age",
"check_answers_card_number": 6,
"type": "numeric",
"min": 0,
"min": 1,
"max": 120,
"step": 1,
"width": 2,
@ -4721,7 +4721,7 @@
"check_answer_label": "Person 7’s age",
"check_answers_card_number": 7,
"type": "numeric",
"min": 0,
"min": 1,
"max": 120,
"step": 1,
"width": 2,
@ -5241,7 +5241,7 @@
"check_answer_label": "Person 8’s age",
"check_answers_card_number": 8,
"type": "numeric",
"min": 0,
"min": 1,
"max": 120,
"step": 1,
"width": 2,

10
lib/tasks/correct_min_age_values.rake

@ -0,0 +1,10 @@
desc "Alter age values from 0 to 1"
task correct_min_age_values: :environment do
LettingsLog.where(age2: 0).update_all(age2: 1, values_updated_at: Time.zone.now)
LettingsLog.where(age3: 0).update_all(age3: 1, values_updated_at: Time.zone.now)
LettingsLog.where(age4: 0).update_all(age4: 1, values_updated_at: Time.zone.now)
LettingsLog.where(age5: 0).update_all(age5: 1, values_updated_at: Time.zone.now)
LettingsLog.where(age6: 0).update_all(age6: 1, values_updated_at: Time.zone.now)
LettingsLog.where(age7: 0).update_all(age7: 1, values_updated_at: Time.zone.now)
LettingsLog.where(age8: 0).update_all(age8: 1, values_updated_at: Time.zone.now)
end

80
spec/lib/tasks/correct_min_age_values_spec.rb

@ -0,0 +1,80 @@
require "rails_helper"
require "rake"
RSpec.describe "correct_min_age_values" do
describe ":correct_min_age_values", type: :task do
subject(:task) { Rake::Task["correct_min_age_values"] }
before do
Rake.application.rake_require("tasks/correct_min_age_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 age2..8 0 to have age2..8 1" do
lettings_log.hhmemb = 8
lettings_log.age2_known = 0
lettings_log.age2 = 0
lettings_log.age3_known = 0
lettings_log.age3 = 0
lettings_log.age4_known = 0
lettings_log.age4 = 0
lettings_log.age5_known = 0
lettings_log.age5 = 0
lettings_log.age6_known = 0
lettings_log.age6 = 0
lettings_log.age7_known = 0
lettings_log.age7 = 0
lettings_log.age8_known = 0
lettings_log.age8 = 0
lettings_log.save!(validate: false)
task.invoke
lettings_log.reload
expect(lettings_log.age2).to eq(1)
expect(lettings_log.age3).to eq(1)
expect(lettings_log.age4).to eq(1)
expect(lettings_log.age5).to eq(1)
expect(lettings_log.age6).to eq(1)
expect(lettings_log.age7).to eq(1)
expect(lettings_log.age8).to eq(1)
expect(lettings_log.values_updated_at).not_to be_nil
end
it "does not update valid age2..8 values" do
lettings_log.hhmemb = 8
lettings_log.age2_known = 0
lettings_log.age2 = 2
lettings_log.age3_known = 0
lettings_log.age3 = 4
lettings_log.age4_known = 0
lettings_log.age4 = 2
lettings_log.age5_known = 0
lettings_log.age5 = 2
lettings_log.age6_known = 0
lettings_log.age6 = 3
lettings_log.age7_known = 0
lettings_log.age7 = 6
lettings_log.age8_known = 0
lettings_log.age8 = 20
lettings_log.save!(validate: false)
task.invoke
lettings_log.reload
expect(lettings_log.age2).to eq(2)
expect(lettings_log.age3).to eq(4)
expect(lettings_log.age4).to eq(2)
expect(lettings_log.age5).to eq(2)
expect(lettings_log.age6).to eq(3)
expect(lettings_log.age7).to eq(6)
expect(lettings_log.age8).to eq(20)
expect(lettings_log.values_updated_at).to be_nil
end
end
end
end
Loading…
Cancel
Save