Browse Source

add vday, vmonth and vyear fields (#403)

pull/405/head
Dushan 3 years ago committed by GitHub
parent
commit
994f45fb96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/case_log.rb
  2. 9
      db/migrate/20220321142903_add_void_date_day_month_year_fields.rb
  3. 3
      db/schema.rb
  4. 3
      spec/factories/case_log.rb
  5. 3
      spec/fixtures/complete_case_log.json
  6. 3
      spec/fixtures/exports/case_logs.xml
  7. 11
      spec/models/case_log_spec.rb

5
app/models/case_log.rb

@ -343,6 +343,11 @@ private
self.month = startdate.month self.month = startdate.month
self.year = startdate.year self.year = startdate.year
end end
if property_void_date.present?
self.vday = property_void_date.day
self.vmonth = property_void_date.month
self.vyear = property_void_date.year
end
self.incref = 1 if net_income_refused? self.incref = 1 if net_income_refused?
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/20220321142903_add_void_date_day_month_year_fields.rb

@ -0,0 +1,9 @@
class AddVoidDateDayMonthYearFields < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :vday, :integer
t.column :vmonth, :integer
t.column :vyear, :integer
end
end
end

3
db/schema.rb

@ -225,6 +225,9 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.decimal "wtcharge", precision: 10, scale: 2 t.decimal "wtcharge", precision: 10, scale: 2
t.decimal "wtshortfall", precision: 10, scale: 2 t.decimal "wtshortfall", precision: 10, scale: 2
t.integer "housingneeds" t.integer "housingneeds"
t.integer "vday"
t.integer "vmonth"
t.integer "vyear"
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"
end end

3
spec/factories/case_log.rb

@ -63,6 +63,9 @@ FactoryBot.define do
unittype_gn { 2 } unittype_gn { 2 }
beds { 3 } beds { 3 }
property_void_date { "03/11/2019" } property_void_date { "03/11/2019" }
vday { 3 }
vmonth { 11 }
vyear { 2019 }
offered { 2 } offered { 2 }
wchair { 1 } wchair { 1 }
earnings { 68 } earnings { 68 }

3
spec/fixtures/complete_case_log.json vendored

@ -64,6 +64,9 @@
"property_building_type": "dummy", "property_building_type": "dummy",
"beds": 3, "beds": 3,
"property_void_date": "10/10/2020", "property_void_date": "10/10/2020",
"vday": 10,
"vmonth": 10,
"vyear": 2020,
"majorrepairs": 1, "majorrepairs": 1,
"mrcdate": "11/11/2020", "mrcdate": "11/11/2020",
"mrcday": 11, "mrcday": 11,

3
spec/fixtures/exports/case_logs.xml vendored

@ -167,5 +167,8 @@
<wtcharge>162.5</wtcharge> <wtcharge>162.5</wtcharge>
<wtshortfall>6.0</wtshortfall> <wtshortfall>6.0</wtshortfall>
<housingneeds>1</housingneeds> <housingneeds>1</housingneeds>
<vday>3</vday>
<vmonth>11</vmonth>
<vyear>2019</vyear>
</form> </form>
</forms> </forms>

11
spec/models/case_log_spec.rb

@ -200,6 +200,7 @@ RSpec.describe CaseLog do
previous_postcode: "M2 2AE", previous_postcode: "M2 2AE",
startdate: Time.gm(2021, 10, 10), startdate: Time.gm(2021, 10, 10),
mrcdate: Time.gm(2021, 5, 4), mrcdate: Time.gm(2021, 5, 4),
property_void_date: Time.gm(2021, 3, 3),
net_income_known: 2, net_income_known: 2,
other_hhmemb: 6, other_hhmemb: 6,
rent_type: 4, rent_type: 4,
@ -231,6 +232,16 @@ RSpec.describe CaseLog do
expect(record_from_db["mrcyear"]).to eq(2021) expect(record_from_db["mrcyear"]).to eq(2021)
end end
it "correctly derives and saves partial and full major property void date" do
record_from_db = ActiveRecord::Base.connection.execute("select vday, vmonth, vyear, property_void_date from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["property_void_date"].day).to eq(3)
expect(record_from_db["property_void_date"].month).to eq(3)
expect(record_from_db["property_void_date"].year).to eq(2021)
expect(record_from_db["vday"]).to eq(3)
expect(record_from_db["vmonth"]).to eq(3)
expect(record_from_db["vyear"]).to eq(2021)
end
it "correctly derives and saves incref" do it "correctly derives and saves incref" do
record_from_db = ActiveRecord::Base.connection.execute("select incref from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select incref from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["incref"]).to eq(1) expect(record_from_db["incref"]).to eq(1)

Loading…
Cancel
Save