Browse Source

Merge branch 'main' into CLDC-1663-remove-housing-provider

# Conflicts:
#	app/controllers/organisation_relationships_controller.rb
#	app/frontend/styles/_accessible-autocomplete.scss
#	app/views/organisation_relationships/add_housing_provider.html.erb
#	app/views/organisation_relationships/housing_providers.html.erb
pull/957/head
natdeanlewissoftwire 3 years ago
parent
commit
766242c0aa
  1. 12
      app/controllers/organisation_relationships_controller.rb
  2. 4
      app/frontend/styles/_accessible-autocomplete.scss
  3. 2
      app/views/form/review.html.erb
  4. 5
      app/views/organisation_relationships/add_housing_provider.html.erb
  5. 12
      app/views/organisation_relationships/housing_providers.html.erb
  6. 106
      spec/requests/organisations_controller_spec.rb

12
app/controllers/organisation_relationships_controller.rb

@ -49,23 +49,19 @@ class OrganisationRelationshipsController < ApplicationController
if related_organisation_id.empty?
@organisation.errors.add :related_organisation_id, "You must choose a housing provider"
@organisations = Organisation.where.not(id: child_organisation_id).pluck(:id, :name)
render 'organisation_relationships/add_housing_provider'
render "organisation_relationships/add_housing_provider"
return
elsif OrganisationRelationship.exists?(child_organisation_id:, parent_organisation_id:, relationship_type:)
@organisation.errors.add :related_organisation_id, "You have already added this housing provider"
@organisations = Organisation.where.not(id: child_organisation_id).pluck(:id, :name)
render 'organisation_relationships/add_housing_provider'
render "organisation_relationships/add_housing_provider"
return
end
create(child_organisation_id:, parent_organisation_id:, relationship_type:)
create!(child_organisation_id:, parent_organisation_id:, relationship_type:)
redirect_to housing_providers_organisation_path(related_organisation_id:)
end
def create_managing_agent
create(child_organisation_id: related_organisation_id, parent_organisation_id: @organisation.id, relationship_type: 1)
end
def create(child_organisation_id:, parent_organisation_id:, relationship_type:)
def create!(child_organisation_id:, parent_organisation_id:, relationship_type:)
@resource = OrganisationRelationship.new(child_organisation_id:, parent_organisation_id:, relationship_type:)
@resource.save!
end

4
app/frontend/styles/_accessible-autocomplete.scss

@ -9,7 +9,7 @@
background-repeat: no-repeat;
background-size: 1em 1em;
background-position: 7px center;
padding-left: govuk-spacing(6) !important;
text-indent: govuk-spacing(6);
}
.autocomplete__option__append {
@ -18,7 +18,7 @@
.autocomplete__hint {
font-family: inherit;
padding-left: govuk-spacing(6) !important;
text-indent: govuk-spacing(6);
}
.autocomplete__option__hint {

2
app/views/form/review.html.erb

@ -1,7 +1,7 @@
<% content_for :title, "Review lettings log" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs",
"Log #{@log.id}" => "/logs/#{@log.id}",
"Log #{@log.id}" => "/lettings-logs/#{@log.id}",
"Review lettings log" => "",
}) %>

5
app/views/organisation_relationships/add_housing_provider.html.erb

@ -20,8 +20,9 @@
<% answer_options[organisation[0]] = organisation[1] %>
<% end %>
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: {
question: Form::Question.new("", {"answer_options" => answer_options}, nil),
f: } %>
question: Form::Question.new("", { "answer_options" => answer_options }, nil),
f:,
} %>
<%= f.govuk_submit "Add" %>
<%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %>
<ul class="govuk-list govuk-list--bullet">

12
app/views/organisation_relationships/housing_providers.html.erb

@ -7,9 +7,10 @@
success: true, title_heading_level: 3,
title_id: "swanky-notifications"
) do |notification_banner|
notification_banner.heading(text: "#{Organisation.find(params["related_organisation_id"]).name} is now one of your housing providers")
end %>
<% end %><% end %>
notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of your housing providers")
end %>
<% end %>
<% end %>
<% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
@ -20,8 +21,8 @@
success: true, title_heading_level: 3,
title_id: "swanky-notifications"
) do |notification_banner|
notification_banner.heading(text: "#{Organisation.find(params["related_organisation_id"]).name} is now one of your housing providers")
end %>
notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of this organisation's housing providers")
end %>
<% end %>
<p class="govuk-body">This organisation can submit logs for its housing providers.</p>
<% if @total_count == 0 %>
@ -35,7 +36,6 @@
<% end %>
<% end %>
<% if current_user.support? %>
<%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path(organisation_id: @organisation.id), html: { method: :get } %>
<% elsif current_user.data_coordinator? %>

106
spec/requests/organisations_controller_spec.rb

@ -534,6 +534,34 @@ RSpec.describe OrganisationsController, type: :request do
expect { request }.not_to change(Organisation, :count)
end
end
describe "organisation_relationships#create_housing_provider" do
let!(:housing_provider) { FactoryBot.create(:organisation) }
let(:params) do
{
"organisation": {
"related_organisation_id": housing_provider.id,
},
}
end
let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: }
it "creates a new organisation relationship" do
expect { request }.to change(OrganisationRelationship, :count).by(1)
end
it "sets the organisation relationship attributes correctly" do
request
expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id, relationship_type: OrganisationRelationship::OWNING)
end
it "redirects to the organisation list" do
request
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers?related_organisation_id=#{housing_provider.id}")
end
end
end
context "with a data provider user" do
@ -1166,6 +1194,56 @@ RSpec.describe OrganisationsController, type: :request do
end
end
context "when viewing a specific organisation's housing providers" do
let!(:housing_provider) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning])
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning])
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {}
end
it "displays the name of the organisation" do
expect(page).to have_content(organisation.name)
end
it "has a sub-navigation with correct tabs" do
expect(page).to have_css(".app-sub-navigation")
expect(page).to have_content("Users")
end
it "shows a table of housing providers" do
expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name)
end
it "shows only housing providers for this organisation" do
expect(page).to have_content(housing_provider.name)
expect(page).not_to have_content(other_org_housing_provider.name)
end
it "shows the pagination count" do
expect(page).to have_content("1 total housing providers")
end
context "when adding a housing provider" do
before do
get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {}
end
it "has the correct header" do
expect(response.body).to include("What is the name of this organisation&#39;s housing provider?")
end
it "shows an add button" do
expect(page).to have_button("Add")
end
end
end
context "when there are more than 20 organisations" do
let(:total_organisations_count) { Organisation.all.count }
@ -1323,6 +1401,34 @@ RSpec.describe OrganisationsController, type: :request do
end
end
end
describe "organisation_relationships#create_housing_provider" do
let!(:housing_provider) { FactoryBot.create(:organisation) }
let(:params) do
{
"organisation": {
"related_organisation_id": housing_provider.id,
},
}
end
let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: }
it "creates a new organisation relationship" do
expect { request }.to change(OrganisationRelationship, :count).by(1)
end
it "sets the organisation relationship attributes correctly" do
request
expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id, relationship_type: OrganisationRelationship::OWNING)
end
it "redirects to the organisation list" do
request
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers?related_organisation_id=#{housing_provider.id}")
end
end
end
end

Loading…
Cancel
Save