Browse Source

Data collection windows don't follow the calendar year (#209)

pull/211/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
daf1211510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/models/case_log.rb
  2. 2
      app/models/form_handler.rb
  3. 2
      spec/factories/case_log.rb
  4. 4
      spec/models/case_log_spec.rb
  5. 4
      spec/requests/form_controller_spec.rb

10
app/models/case_log.rb

@ -142,8 +142,14 @@ class CaseLog < ApplicationRecord
end
def form_name
start_year = year || 2021
"#{start_year}_#{start_year + 1}"
return "2021_2022" unless startdate
window_end_date = Time.zone.local(startdate.year, 4, 1)
if startdate < window_end_date
"#{startdate.year - 1}_#{startdate.year}"
else
"#{startdate.year}_#{startdate.year + 1}"
end
end
def self.editable_fields

2
app/models/form_handler.rb

@ -7,7 +7,7 @@ class FormHandler
end
def get_form(form)
@forms[form] ||= Form.new(form)
@forms[form]
end
private

2
spec/factories/case_log.rb

@ -8,7 +8,7 @@ FactoryBot.define do
tenant_same_property_renewal { "No" }
needstype { 1 }
rent_type { 1 }
startdate { Time.zone.local(2022, 1, 1) }
startdate { Time.zone.local(2022, 5, 1) }
year { 2022 }
end
trait :in_progress do

4
spec/models/case_log_spec.rb

@ -10,9 +10,11 @@ RSpec.describe Form, type: :model do
describe "#form" do
let(:case_log) { FactoryBot.build(:case_log) }
let(:case_log_year_2) { FactoryBot.build(:case_log, year: 2023) }
let(:case_log_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2022, 1, 1)) }
let(:case_log_year_2) { FactoryBot.build(:case_log, startdate: Time.zone.local(2023, 5, 1)) }
it "has returns the correct form based on the start date" do
expect(case_log.form_name).to eq("2021_2022")
expect(case_log_2.form_name).to eq("2021_2022")
expect(case_log_year_2.form_name).to eq("2023_2024")
expect(case_log.form).to be_a(Form)
end

4
spec/requests/form_controller_spec.rb

@ -49,8 +49,8 @@ RSpec.describe FormController, type: :request do
describe "GET" do
context "form pages" do
context "forms exist for multiple years" do
let(:case_log_year_1) { FactoryBot.create(:case_log, startdate: Time.zone.local(2021, 1, 1), owning_organisation: organisation) }
let(:case_log_year_2) { FactoryBot.create(:case_log, :about_completed, startdate: Time.zone.local(2022, 1, 1), owning_organisation: organisation) }
let(:case_log_year_1) { FactoryBot.create(:case_log, startdate: Time.zone.local(2021, 5, 1), owning_organisation: organisation) }
let(:case_log_year_2) { FactoryBot.create(:case_log, :about_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation) }
it "displays the correct question details for each case log based on form year" do
get "/logs/#{case_log_year_1.id}/tenant-code", headers: headers, params: {}

Loading…
Cancel
Save