Browse Source

Cldc 650 derived startdate (#164)

* add fields for deriving startdate

* Add test for inferring startdate, fix other tests

* infer day, month, year instead
pull/162/head^2
Dushan 3 years ago committed by GitHub
parent
commit
831f59c6da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/case_log.rb
  2. 9
      db/migrate/20211213122642_add_day_month_year_fields_for_start_date.rb
  3. 5
      db/schema.rb
  4. 3
      spec/factories/case_log.rb
  5. 3
      spec/fixtures/complete_case_log.json
  6. 13
      spec/models/case_log_spec.rb

5
app/models/case_log.rb

@ -184,6 +184,11 @@ private
self.mrcmonth = mrcdate.month self.mrcmonth = mrcdate.month
self.mrcyear = mrcdate.year self.mrcyear = mrcdate.year
end end
if startdate.present?
self.day = startdate.day
self.month = startdate.month
self.year = startdate.year
end
self.incref = 1 if net_income_known == "Prefer not to say" self.incref = 1 if net_income_known == "Prefer not to say"
self.hhmemb = other_hhmemb + 1 if other_hhmemb.present? self.hhmemb = other_hhmemb + 1 if other_hhmemb.present?
self.renttype = RENT_TYPE_MAPPING[rent_type] self.renttype = RENT_TYPE_MAPPING[rent_type]

9
db/migrate/20211213122642_add_day_month_year_fields_for_start_date.rb

@ -0,0 +1,9 @@
class AddDayMonthYearFieldsForStartDate < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.column :day, :integer
t.column :month, :integer
t.column :year, :integer
end
end
end

5
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_12_03_144855) do ActiveRecord::Schema.define(version: 2021_12_13_122642) 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"
@ -171,6 +171,9 @@ ActiveRecord::Schema.define(version: 2021_12_03_144855) do
t.integer "lettype" t.integer "lettype"
t.integer "postcode_known" t.integer "postcode_known"
t.integer "la_known" t.integer "la_known"
t.integer "day"
t.integer "month"
t.integer "year"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"

3
spec/factories/case_log.rb

@ -134,6 +134,9 @@ FactoryBot.define do
incref { 0 } incref { 0 }
sale_completion_date { nil } sale_completion_date { nil }
startdate { Time.zone.now } startdate { Time.zone.now }
day { Time.zone.now.day }
month { Time.zone.now.month }
year { Time.zone.now.year }
armedforces { 1 } armedforces { 1 }
builtype { 1 } builtype { 1 }
unitletas { 2 } unitletas { 2 }

3
spec/fixtures/complete_case_log.json vendored

@ -51,6 +51,9 @@
"condition_effects": "dummy", "condition_effects": "dummy",
"tenancy_code": "BZ757", "tenancy_code": "BZ757",
"startdate": "12/12/2020", "startdate": "12/12/2020",
"day": 12,
"month": 12,
"year": 2020,
"startertenancy": "No", "startertenancy": "No",
"tenancylength": "5", "tenancylength": "5",
"tenancy": "Secure (including flexible)", "tenancy": "Secure (including flexible)",

13
spec/models/case_log_spec.rb

@ -937,6 +937,7 @@ RSpec.describe Form, type: :model do
property_postcode: "M1 1AE", property_postcode: "M1 1AE",
previous_postcode: "M2 2AE", previous_postcode: "M2 2AE",
# rubocop:disable Style/DateTime # rubocop:disable Style/DateTime
startdate: DateTime.new(2021, 10, 10),
mrcdate: DateTime.new(2021, 5, 4), mrcdate: DateTime.new(2021, 5, 4),
# rubocop:enable Style/DateTime # rubocop:enable Style/DateTime
net_income_known: "Prefer not to say", net_income_known: "Prefer not to say",
@ -1003,5 +1004,17 @@ RSpec.describe Form, type: :model do
expect(case_log.lettype).to eq("Intermediate Rent General needs PRP") expect(case_log.lettype).to eq("Intermediate Rent General needs PRP")
expect(record_from_db["lettype"]).to eq(9) expect(record_from_db["lettype"]).to eq(9)
end end
it "correctly derives and saves day, month, year from start date" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select day, month, year, startdate from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["startdate"].day).to eq(10)
expect(record_from_db["startdate"].month).to eq(10)
expect(record_from_db["startdate"].year).to eq(2021)
expect(record_from_db["day"]).to eq(10)
expect(record_from_db["month"]).to eq(10)
expect(record_from_db["year"]).to eq(2021)
end
end end
end end

Loading…
Cancel
Save