Browse Source

Save mcr date as datetime, fix saving the dates (#85)

pull/86/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
20bda98d4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/admin/case_logs.rb
  2. 6
      app/controllers/case_logs_controller.rb
  3. 20
      app/models/case_log.rb
  4. 4
      config/forms/2021_2022.json
  5. 21
      db/migrate/20211110140928_add_mrc_dates.rb
  6. 7
      db/schema.rb
  7. 6
      docs/api/DLUHC-CORE-Data.v1.json
  8. 22
      spec/controllers/case_logs_controller_spec.rb
  9. 5
      spec/fixtures/complete_case_log.json
  10. 10
      spec/fixtures/forms/test_form.json
  11. 2
      spec/models/form_handler_spec.rb

2
app/admin/case_logs.rb

@ -2,7 +2,7 @@ ActiveAdmin.register CaseLog do
# See permitted parameters documentation: # See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
permit_params do permit_params do
permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider la previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date majorrepairs property_major_repairs_date property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion hb rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge tshortfall time_lived_in_la time_on_la_waiting_list prevloc property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting hbrentshortfall other_reason accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known] permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider la previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date majorrepairs mrcdate property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion hb rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge tshortfall time_lived_in_la time_on_la_waiting_list prevloc property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting hbrentshortfall other_reason accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known]
permitted permitted
end end

6
app/controllers/case_logs_controller.rb

@ -103,6 +103,12 @@ private
form = FormHandler.instance.get_form("2021_2022") form = FormHandler.instance.get_form("2021_2022")
form.expected_responses_for_page(page).each_with_object({}) do |(question_key, question_info), result| form.expected_responses_for_page(page).each_with_object({}) do |(question_key, question_info), result|
question_params = params["case_log"][question_key] question_params = params["case_log"][question_key]
if question_info["type"] == "date"
day = params["case_log"]["#{question_key}(3i)"]
month = params["case_log"]["#{question_key}(2i)"]
year = params["case_log"]["#{question_key}(1i)"]
result[question_key] = Date.new(year.to_i, month.to_i, day.to_i)
end
next unless question_params next unless question_params
if %w[checkbox validation_override].include?(question_info["type"]) if %w[checkbox validation_override].include?(question_info["type"])

20
app/models/case_log.rb

@ -169,6 +169,26 @@ class CaseLog < ApplicationRecord
IncomeRange::ALLOWED[ecstat1.to_sym] IncomeRange::ALLOWED[ecstat1.to_sym]
end end
def mrcday
if mrcdate.present?
mrcdate.day
end
end
def mrcmonth
if mrcdate.present?
mrcdate.month
end
end
def mrcyear
if mrcdate.present?
mrcdate.year
end
end
private private
def update_status! def update_status!

4
config/forms/2021_2022.json

@ -1585,10 +1585,10 @@
"1": "No" "1": "No"
}, },
"conditional_for": { "conditional_for": {
"property_major_repairs_date": ["Yes"] "mrcdate": ["Yes"]
} }
}, },
"property_major_repairs_date": { "mrcdate": {
"check_answer_label": "What was the major repairs completion date?", "check_answer_label": "What was the major repairs completion date?",
"header": "What was the major repairs completion date?", "header": "What was the major repairs completion date?",
"hint_text": "For example, 27 3 2007", "hint_text": "For example, 27 3 2007",

21
db/migrate/20211110140928_add_mrc_dates.rb

@ -0,0 +1,21 @@
class AddMrcDates < ActiveRecord::Migration[6.1]
def up
change_table :case_logs, bulk: true do |t|
t.remove :property_major_repairs_date
t.column :mrcdate, :datetime
t.column :mrcday, :integer
t.column :mrcmonth, :integer
t.column :mrcyear, :integer
end
end
def down
change_table :case_logs, bulk: true do |t|
t.column :property_major_repairs_date, :string
t.remove :mrcdate
t.remove :mrcday
t.remove :mrcmonth
t.remove :mrcyear
end
end
end

7
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_11_08_134601) do ActiveRecord::Schema.define(version: 2021_11_10_140928) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -78,7 +78,6 @@ ActiveRecord::Schema.define(version: 2021_11_08_134601) do
t.string "property_building_type" t.string "property_building_type"
t.integer "beds" t.integer "beds"
t.string "property_void_date" t.string "property_void_date"
t.string "property_major_repairs_date"
t.integer "offered" t.integer "offered"
t.integer "wchair" t.integer "wchair"
t.integer "earnings" t.integer "earnings"
@ -149,6 +148,10 @@ ActiveRecord::Schema.define(version: 2021_11_08_134601) do
t.string "ppostc1" t.string "ppostc1"
t.string "ppostc2" t.string "ppostc2"
t.integer "property_relet" t.integer "property_relet"
t.datetime "mrcdate"
t.integer "mrcday"
t.integer "mrcmonth"
t.integer "mrcyear"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
end end

6
docs/api/DLUHC-CORE-Data.v1.json

@ -319,7 +319,7 @@
"beds": 3, "beds": 3,
"property_void_date": "03/11/2019", "property_void_date": "03/11/2019",
"majorrepairs": "Yes", "majorrepairs": "Yes",
"property_major_repairs_date": "05/05/2020", "mrcdate": "05/05/2020",
"offered": 2, "offered": 2,
"wchair": true, "wchair": true,
"earnings": 1000, "earnings": 1000,
@ -875,7 +875,7 @@
"type": "string", "type": "string",
"minLength": 1 "minLength": 1
}, },
"property_major_repairs_date": { "mrcdate": {
"type": "string", "type": "string",
"minLength": 1 "minLength": 1
}, },
@ -1108,7 +1108,7 @@
"beds", "beds",
"property_void_date", "property_void_date",
"majorrepairs", "majorrepairs",
"property_major_repairs_date", "mrcdate",
"offered", "offered",
"wchair", "wchair",
"earnings", "earnings",

22
spec/controllers/case_logs_controller_spec.rb

@ -177,6 +177,28 @@ RSpec.describe CaseLogsController, type: :controller do
expect(case_log.ppostc2).to eq("2AE") expect(case_log.ppostc2).to eq("2AE")
end end
end end
context "partition date" do
let(:case_log_with_date) do
{
:"mrcdate(1i)" => "2021",
:"mrcdate(2i)" => "05",
:"mrcdate(3i)" => "04",
:page => "major_repairs_date",
}
end
it "saves full and partial dates" do
post :submit_form, params: { id: id, case_log: case_log_with_date }
case_log.reload
expect(case_log.mrcdate.day).to eq(4)
expect(case_log.mrcdate.month).to eq(5)
expect(case_log.mrcdate.year).to eq(2021)
expect(case_log.mrcday).to eq(4)
expect(case_log.mrcmonth).to eq(5)
expect(case_log.mrcyear).to eq(2021)
end
end
end end
describe "get_next_page_path" do describe "get_next_page_path" do

5
spec/fixtures/complete_case_log.json vendored

@ -64,7 +64,10 @@
"beds": 3, "beds": 3,
"property_void_date": "03/11/2019", "property_void_date": "03/11/2019",
"majorrepairs": "Yes", "majorrepairs": "Yes",
"property_major_repairs_date": "05/05/2020", "mrcdate": "05/05/2020",
"mrcday": 5,
"mrcmonth": 5,
"mrcyear": 2020,
"offered": 2, "offered": 2,
"wchair": "Yes", "wchair": "Yes",
"net_income_known": "Yes", "net_income_known": "Yes",

10
spec/fixtures/forms/test_form.json vendored

@ -510,6 +510,16 @@
"type": "text" "type": "text"
} }
} }
},
"major_repairs_date": {
"questions": {
"mrcdate": {
"check_answer_label": "What was the major repairs completion date?",
"header": "What was the major repairs completion date?",
"hint_text": "For example, 27 3 2007",
"type": "date"
}
}
} }
} }
} }

2
spec/models/form_handler_spec.rb

@ -15,7 +15,7 @@ RSpec.describe FormHandler do
form_handler = FormHandler.instance form_handler = FormHandler.instance
form = form_handler.get_form("test_form") form = form_handler.get_form("test_form")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.all_pages.count).to eq(22) expect(form.all_pages.count).to eq(23)
end end
end end

Loading…
Cancel
Save