diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 6672d79c2..d2ab06662 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -94,6 +94,8 @@ class OrganisationsController < ApplicationController def edit if current_user.data_coordinator? || current_user.support? + checked_periods = @organisation.organisation_rent_periods.map(&:rent_period).map(&:to_s) + @rent_periods = helpers.rent_periods_with_checked_attr(checked_periods:) render "edit", layout: "application" else head :unauthorized diff --git a/app/helpers/organisations_helper.rb b/app/helpers/organisations_helper.rb index fd056b9bd..bb32bea51 100644 --- a/app/helpers/organisations_helper.rb +++ b/app/helpers/organisations_helper.rb @@ -16,7 +16,7 @@ module OrganisationsHelper { name: "Telephone number", value: organisation.phone, editable: true }, { name: "Type of provider", value: organisation.display_provider_type, editable: false }, { name: "Registration number", value: organisation.housing_registration_no || "", editable: false }, - { name: "Rent periods", value: organisation.rent_period_labels, editable: false, format: :bullet }, + { name: "Rent periods", value: organisation.rent_period_labels, editable: true, format: :bullet }, { name: "Owns housing stock", value: organisation.holds_own_stock ? "Yes" : "No", editable: false }, { name: "Status", value: status_tag(organisation.status), editable: false }, ] diff --git a/app/views/organisations/edit.html.erb b/app/views/organisations/edit.html.erb index 21297ec86..f3ec89ff4 100644 --- a/app/views/organisations/edit.html.erb +++ b/app/views/organisations/edit.html.erb @@ -32,6 +32,17 @@ autocomplete: "tel", width: 20 %> + <%= f.govuk_check_boxes_fieldset :rent_periods, + legend: { text: "What are the rent periods for the organisation?" } do %> + <% @rent_periods.map do |key, period| %> + <%= f.govuk_check_box :rent_periods, + key, + label: { text: period["value"] }, + checked: period[:checked] + %> + <% end %> + <% end %> + <%= f.govuk_submit "Save changes" %> diff --git a/spec/helpers/organisations_helper_spec.rb b/spec/helpers/organisations_helper_spec.rb index f7a3653a4..12d137acd 100644 --- a/spec/helpers/organisations_helper_spec.rb +++ b/spec/helpers/organisations_helper_spec.rb @@ -14,7 +14,7 @@ RSpec.describe OrganisationsHelper do { editable: true, name: "Telephone number", value: nil }, { editable: false, name: "Type of provider", value: "Local authority" }, { editable: false, name: "Registration number", value: "1234" }, - { editable: false, format: :bullet, name: "Rent periods", value: %w[All] }, + { editable: true, format: :bullet, name: "Rent periods", value: %w[All] }, { editable: false, name: "Owns housing stock", value: "Yes" }, { editable: false, name: "Status", value: status_tag(organisation.status) }], ) diff --git a/spec/requests/OrganisationsController/organisations_controller_rent_periods_spec.rb b/spec/requests/OrganisationsController/organisations_controller_rent_periods_spec.rb index 1c4d70fe8..6f317baa8 100644 --- a/spec/requests/OrganisationsController/organisations_controller_rent_periods_spec.rb +++ b/spec/requests/OrganisationsController/organisations_controller_rent_periods_spec.rb @@ -51,4 +51,33 @@ RSpec.describe OrganisationsController, type: :request do expect(org_rent_periods.map(&:organisation_id)).to all be org.id end end + + describe "#edit" do + let(:organisation) { create(:organisation) } + let(:fake_rent_periods) do + { + "1" => { "value" => "Every minute" }, + "2" => { "value" => "Every decade" }, + } + end + let(:checked_rent_period_id) { "1" } + + before do + create(:organisation_rent_period, organisation:, rent_period: checked_rent_period_id) + get edit_organisation_path organisation + end + + it "displays the rent periods question" do + expect(page).to have_content "What are the rent periods for the organisation?" + end + + it "the checkboxes for each rent period are checked where appropriate" do + checkboxes = page.all "input[type='checkbox']" + expect(checkboxes.count).to be 2 + expected_checked_checkbox = checkboxes.find { |cb| cb[:value] == checked_rent_period_id } + expect(expected_checked_checkbox[:checked]).to be true + expected_not_checked_checkbox = checkboxes.find { |cb| cb[:value] != checked_rent_period_id } + expect(expected_not_checked_checkbox[:checked]).to be false + end + end end