diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 824b0efff..755615e8b 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -416,6 +416,8 @@ private self["ecstat#{idx}"] = nil end end + self.landlord = 1 if owning_organisation.provider_type == "LA" + self.landlord = 2 if owning_organisation.provider_type == "PRP" end def process_postcode_changes! diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index dcfa683d0..2089965a1 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -53,7 +53,7 @@ "startertenancy": 0, "tenancylength": 5, "tenancy": 3, - "landlord": "This landlord", + "landlord": 1, "la": "Barnet", "postcode_full": "NW1 5TY", "property_relet": 0, diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 5777f4306..f69536cb3 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -258,6 +258,24 @@ RSpec.describe CaseLog do expect(record_from_db["renttype"]).to eq(3) end + context "when the owning organisation is a PRP" do + it "correctly derives and saves landlord based on owning_organisation provider_type" do + record_from_db = ActiveRecord::Base.connection.execute("select landlord from case_logs where id=#{case_log.id}").to_a[0] + expect(case_log.landlord).to eq(2) + expect(record_from_db["landlord"]).to eq(2) + end + end + + context "when the owning organisation is an LA" do + let(:organisation) { FactoryBot.create(:organisation) } + + it "correctly derives and saves landlord based on owning_organisation provider_type" do + record_from_db = ActiveRecord::Base.connection.execute("select landlord from case_logs where id=#{case_log.id}").to_a[0] + expect(case_log.landlord).to eq(1) + expect(record_from_db["landlord"]).to eq(1) + end + end + context "when deriving lettype" do context "when the owning organisation is a PRP" do context "when the rent type is intermediate rent and supported housing" do