Browse Source

enable editing rent period in the UI

display change button on org details page
display rent periods question on edit page
pull/2389/head
Arthur Campbell 2 years ago
parent
commit
4933473ec4
  1. 2
      app/controllers/organisations_controller.rb
  2. 2
      app/helpers/organisations_helper.rb
  3. 11
      app/views/organisations/edit.html.erb
  4. 2
      spec/helpers/organisations_helper_spec.rb
  5. 29
      spec/requests/OrganisationsController/organisations_controller_rent_periods_spec.rb

2
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

2
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 },
]

11
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" %>
</div>
</div>

2
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) }],
)

29
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

Loading…
Cancel
Save