Browse Source

infer day, month, year instead

pull/164/head
MadeTech Dushan 4 years ago
parent
commit
fcbb4c6099
  1. 6
      app/models/case_log.rb
  2. 16
      spec/models/case_log_spec.rb

6
app/models/case_log.rb

@ -183,8 +183,10 @@ private
self.mrcmonth = mrcdate.month
self.mrcyear = mrcdate.year
end
if day.present? && month.present? && year.present?
self.startdate = Time.zone.local(year, month, day)
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.hhmemb = other_hhmemb + 1 if other_hhmemb.present?

16
spec/models/case_log_spec.rb

@ -881,10 +881,8 @@ RSpec.describe Form, type: :model do
owning_organisation: organisation,
property_postcode: "M1 1AE",
previous_postcode: "M2 2AE",
day: 10,
month: 10,
year: 2021,
# rubocop:disable Style/DateTime
startdate: DateTime.new(2021, 10, 10),
mrcdate: DateTime.new(2021, 5, 4),
# rubocop:enable Style/DateTime
net_income_known: "Prefer not to say",
@ -952,12 +950,16 @@ RSpec.describe Form, type: :model do
expect(record_from_db["lettype"]).to eq(9)
end
it "correctly derives and saves startdate" do
it "correctly derives and saves day, month, year from start date" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select startdate from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.startdate).to eq(Time.zone.local(2021, 10, 10))
expect(record_from_db["startdate"]).to eq(Time.zone.local(2021, 10, 10))
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

Loading…
Cancel
Save