Browse Source

Display Org rent periods

pull/487/head
baarkerlounger 3 years ago
parent
commit
1e335f4948
  1. 11
      app/models/organisation.rb
  2. 5
      app/models/rent_period.rb
  3. 13
      spec/models/organisation_spec.rb
  4. 16
      spec/models/rent_period_spec.rb

11
app/models/organisation.rb

@ -38,13 +38,21 @@ class Organisation < ApplicationRecord
end end
def local_authorities def local_authorities
organisation_las.pluck(:ons_code).map { |ons_code| ons_code } organisation_las.pluck(:ons_code)
end end
def local_authority_names def local_authority_names
local_authorities.map { |ons_code| LocalAuthority.ons_code_mappings[ons_code] } local_authorities.map { |ons_code| LocalAuthority.ons_code_mappings[ons_code] }
end end
def rent_periods
organisation_rent_periods.pluck(:rent_period)
end
def rent_period_labels
rent_periods.map { |period| RentPeriod.rent_period_mappings[period.to_s]["value"] }
end
def display_attributes def display_attributes
[ [
{ name: "name", value: name, editable: true }, { name: "name", value: name, editable: true },
@ -52,6 +60,7 @@ class Organisation < ApplicationRecord
{ name: "telephone_number", value: phone, editable: true }, { name: "telephone_number", value: phone, editable: true },
{ name: "type", value: "Org type", editable: false }, { name: "type", value: "Org type", editable: false },
{ name: "local_authorities_operated_in", value: local_authority_names, editable: false, format: :bullet }, { name: "local_authorities_operated_in", value: local_authority_names, editable: false, format: :bullet },
{ name: "rent_periods", value: rent_period_labels, editable: false, format: :bullet },
{ name: "holds_own_stock", value: holds_own_stock.to_s.humanize, editable: false }, { name: "holds_own_stock", value: holds_own_stock.to_s.humanize, editable: false },
{ name: "other_stock_owners", value: other_stock_owners, editable: false }, { name: "other_stock_owners", value: other_stock_owners, editable: false },
{ name: "managing_agents", value: managing_agents, editable: false }, { name: "managing_agents", value: managing_agents, editable: false },

5
app/models/rent_period.rb

@ -0,0 +1,5 @@
class RentPeriod
def self.rent_period_mappings
FormHandler.instance.current_form.get_question("period", nil).answer_options
end
end

13
spec/models/organisation_spec.rb

@ -58,13 +58,22 @@ RSpec.describe Organisation, type: :model do
end end
context "when the organisation only uses specific rent periods" do context "when the organisation only uses specific rent periods" do
let(:rent_period_mappings) do
{ "2" => { "value" => "Weekly for 52 weeks" }, "3" => { "value" => "Every 2 weeks" } }
end
before do before do
FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 1)
FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 2) FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 2)
FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 3)
allow(RentPeriod).to receive(:rent_period_mappings).and_return(rent_period_mappings)
end end
it "has rent periods associated" do it "has rent periods associated" do
expect(organisation.organisation_rent_periods.pluck("rent_period")).to eq([1, 2]) expect(organisation.rent_periods).to eq([2, 3])
end
it "maps the rent periods to display values" do
expect(organisation.rent_period_labels).to eq(["Weekly for 52 weeks", "Every 2 weeks"])
end end
end end

16
spec/models/rent_period_spec.rb

@ -0,0 +1,16 @@
require "rails_helper"
RSpec.describe RentPeriod, type: :model do
describe "rent period mapping" do
let(:form) { Form.new("spec/fixtures/forms/2021_2022.json", "2021_2022") }
before do
allow(FormHandler.instance).to receive(:current_form).and_return(form)
end
it "maps rent period id to display names" do
expect(described_class.rent_period_mappings).to be_a(Hash)
expect(described_class.rent_period_mappings["2"]).to eq({ "value" => "Weekly for 52 weeks" })
end
end
end
Loading…
Cancel
Save