Browse Source

change housing provider -> stock owner

pull/1104/head
natdeanlewissoftwire 4 years ago
parent
commit
2d975258bd
  1. 4
      app/controllers/organisation_relationships_controller.rb
  2. 2
      app/views/organisation_relationships/_housing_provider_list.erb
  3. 10
      app/views/organisation_relationships/add_housing_provider.html.erb
  4. 18
      app/views/organisation_relationships/housing_providers.html.erb
  5. 4
      app/views/organisation_relationships/remove_housing_provider.html.erb
  6. 10
      spec/models/form/lettings/questions/housing_provider_spec.rb
  7. 2
      spec/requests/form_controller_spec.rb
  8. 42
      spec/requests/organisation_relationships_controller_spec.rb

4
app/controllers/organisation_relationships_controller.rb

@ -42,7 +42,7 @@ class OrganisationRelationshipsController < ApplicationController
def create_housing_provider def create_housing_provider
@organisation_relationship = organisation.parent_organisation_relationships.new(organisation_relationship_params) @organisation_relationship = organisation.parent_organisation_relationships.new(organisation_relationship_params)
if @organisation_relationship.save(context: :housing_provider) if @organisation_relationship.save(context: :housing_provider)
flash[:notice] = "#{@organisation_relationship.parent_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" flash[:notice] = "#{@organisation_relationship.parent_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners"
redirect_to housing_providers_organisation_path redirect_to housing_providers_organisation_path
else else
@organisations = Organisation.where.not(id: organisation.id).pluck(:id, :name) @organisations = Organisation.where.not(id: organisation.id).pluck(:id, :name)
@ -68,7 +68,7 @@ class OrganisationRelationshipsController < ApplicationController
child_organisation: organisation, child_organisation: organisation,
parent_organisation: target_organisation, parent_organisation: target_organisation,
).destroy! ).destroy!
flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners"
redirect_to housing_providers_organisation_path redirect_to housing_providers_organisation_path
end end

2
app/views/organisation_relationships/_housing_provider_list.erb

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> <section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %> <%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "housing providers", path: request.path)) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "stock owners", path: request.path)) %>
<% end %> <% end %>
<% @housing_providers.each do |housing_provider| %> <% @housing_providers.each do |housing_provider| %>
<%= table.body do |body| %> <%= table.body do |body| %>

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

@ -4,14 +4,14 @@
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
<h2 class="govuk-visually-hidden">Add Housing Provider</h2> <h2 class="govuk-visually-hidden">Add Housing Provider</h2>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's housing provider?", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's stock owner?", sub: nil } %>
<p class="govuk-body">Start typing to search for a housing provider</p> <p class="govuk-body">Start typing to search for a stock owner</p>
<% else %> <% else %>
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<% end %> <% end %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "What is the name of your stock owner?", sub: nil } %>
<p class="govuk-body">Start typing to search for your housing provider</p> <p class="govuk-body">Start typing to search for your stock owner</p>
<% end %> <% end %>
<% answer_options = { "" => "Select an option" } %> <% answer_options = { "" => "Select an option" } %>
<% @organisations.each do |organisation| %> <% @organisations.each do |organisation| %>
@ -23,7 +23,7 @@
f:, f:,
} %> } %>
<%= f.govuk_submit "Add" %> <%= f.govuk_submit "Add" %>
<%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %> <%= govuk_details(summary_text: "Can't find the stock owner you're looking for?") do %>
<ul class="govuk-list govuk-list--bullet"> <ul class="govuk-list govuk-list--bullet">
<li>Double check the spelling and try again</li> <li>Double check the spelling and try again</li>
<li>Type the first few letters to see the suggestions</li> <li>Type the first few letters to see the suggestions</li>

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

@ -1,24 +1,24 @@
<% item_label = format_label(@pagy.count, "housing providers") %> <% item_label = format_label(@pagy.count, "stock owners") %>
<% if current_user.support? %> <% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
<h2 class="govuk-visually-hidden">Housing Providers</h2> <h2 class="govuk-visually-hidden">Housing Providers</h2>
<p class="govuk-body">This organisation can submit logs for its housing providers.</p> <p class="govuk-body">This organisation can submit logs for its stock owners.</p>
<% if @total_count == 0 %> <% if @total_count == 0 %>
<p class="govuk-body">This organisation does not currently have any housing providers.</p> <p class="govuk-body">This organisation does not currently have any stock owners.</p>
<% end %> <% end %>
<% else %> <% else %>
<%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: current_user.organisation.name } %> <%= render partial: "organisations/headings", locals: { main: "Your stock owners", sub: current_user.organisation.name } %>
<p class="govuk-body">Your organisation can submit logs for its housing providers.</p> <p class="govuk-body">Your organisation can submit logs for its stock owners.</p>
<% if @total_count == 0 %> <% if @total_count == 0 %>
<p class="govuk-body">You do not currently have any housing providers.</p> <p class="govuk-body">You do not currently have any stock owners.</p>
<% end %> <% end %>
<% end %> <% end %>
<% if current_user.support? || current_user.data_coordinator? %> <% if current_user.support? || current_user.data_coordinator? %>
<%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path, html: { method: :get } %> <%= govuk_button_link_to "Add a stock owner", housing_providers_add_organisation_path, html: { method: :get } %>
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search for a stock owner", value: @searched) %>
<%= render partial: "organisation_relationships/housing_provider_list", locals: { index: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> <%= render partial: "organisation_relationships/housing_provider_list", locals: { index: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %> <%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "stock owners" } %>
<% end %> <% end %>

4
app/views/organisation_relationships/remove_housing_provider.html.erb

@ -6,12 +6,12 @@
<% end %> <% end %>
<% if current_user.support? %> <% if current_user.support? %>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from this organisation's housing providers", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from this organisation's stock owners", sub: nil } %>
<% else %> <% else %>
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<% end %> <% end %>
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from your organisation's housing providers", sub: nil } %> <%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from your organisation's stock owners", sub: nil } %>
<% end %> <% end %>
<%= govuk_warning_text text: "You will no longer be able to submit logs for #{@target_organisation.name}" %> <%= govuk_warning_text text: "You will no longer be able to submit logs for #{@target_organisation.name}" %>
<div class="govuk-button-group"> <div class="govuk-button-group">

10
spec/models/form/lettings/questions/housing_provider_spec.rb

@ -55,7 +55,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
question.current_user = user question.current_user = user
end end
it "shows housing providers with own org at the top" do it "shows stock owners with own org at the top" do
expect(question.answer_options).to eq(options) expect(question.answer_options).to eq(options)
end end
end end
@ -94,7 +94,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
context "when org holds own stock", :aggregate_failures do context "when org holds own stock", :aggregate_failures do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) } let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) }
context "when housing providers == 0" do context "when stock owners == 0" do
before do before do
user.organisation.housing_providers.delete_all user.organisation.housing_providers.delete_all
end end
@ -105,7 +105,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
end end
end end
context "when housing providers != 0" do context "when stock owners != 0" do
before do before do
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
end end
@ -120,7 +120,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
context "when org does not hold own stock", :aggregate_failures do context "when org does not hold own stock", :aggregate_failures do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) } let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) }
context "when housing providers <= 1" do context "when stock owners <= 1" do
before do before do
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
end end
@ -131,7 +131,7 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
end end
end end
context "when housing providers >= 2" do context "when stock owners >= 2" do
before do before do
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)
create(:organisation_relationship, child_organisation: user.organisation) create(:organisation_relationship, child_organisation: user.organisation)

2
spec/requests/form_controller_spec.rb

@ -162,7 +162,7 @@ RSpec.describe FormController, type: :request do
end end
end end
context "with only adding the housing provider" do context "with only adding the stock owner" do
let(:params) do let(:params) do
{ {
id: lettings_log.id, id: lettings_log.id,

42
spec/requests/organisation_relationships_controller_spec.rb

@ -14,7 +14,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
sign_in user sign_in user
end end
context "when accessing the housing providers tab" do context "when accessing the stock owners tab" do
context "with an organisation that the user belongs to" do context "with an organisation that the user belongs to" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:housing_provider) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") }
@ -31,32 +31,32 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
end end
it "shows an add housing provider button" do it "shows an add stock owner button" do
expect(page).to have_link("Add a housing provider") expect(page).to have_link("Add a stock owner")
end end
it "shows a table of housing providers" do it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name) expect(response.body).to include(housing_provider.name)
end end
it "shows only housing providers for the current user's organisation" do it "shows only stock owners for the current user's organisation" do
expect(page).to have_content(housing_provider.name) expect(page).to have_content(housing_provider.name)
expect(page).not_to have_content(other_org_housing_provider.name) expect(page).not_to have_content(other_org_housing_provider.name)
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total housing providers") expect(page).to have_content("1 total stock owners")
end end
context "when adding a housing provider" do context "when adding a stock owner" do
before do before do
get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {} get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {}
end end
it "has the correct header" do it "has the correct header" do
expect(response.body).to include("What is the name of your housing provider?") expect(response.body).to include("What is the name of your stock owner?")
end end
it "shows an add button" do it "shows an add button" do
@ -248,7 +248,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
sign_in user sign_in user
end end
context "when accessing the housing providers tab" do context "when accessing the stock owners tab" do
context "with an organisation that the user belongs to" do context "with an organisation that the user belongs to" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:housing_provider) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") }
@ -265,23 +265,23 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
end end
it "doesn't show an add housing provider button" do it "doesn't show an add stock owner button" do
expect(page).not_to have_link("Add a housing provider") expect(page).not_to have_link("Add a stock owner")
end end
it "shows a table of housing providers" do it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name) expect(response.body).to include(housing_provider.name)
end end
it "shows only housing providers for the current user's organisation" do it "shows only stock owners for the current user's organisation" do
expect(page).to have_content(housing_provider.name) expect(page).to have_content(housing_provider.name)
expect(page).not_to have_content(other_org_housing_provider.name) expect(page).not_to have_content(other_org_housing_provider.name)
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total housing providers") expect(page).to have_content("1 total stock owners")
end end
end end
@ -469,7 +469,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
end end
context "when viewing a specific organisation's housing providers" do context "when viewing a specific organisation's stock owners" do
let!(:housing_provider) { FactoryBot.create(:organisation) } let!(:housing_provider) { FactoryBot.create(:organisation) }
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") } let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
@ -489,13 +489,13 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(page).to have_content("Users") expect(page).to have_content("Users")
end end
it "shows a table of housing providers" do it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(housing_provider.name) expect(response.body).to include(housing_provider.name)
end end
it "shows only housing providers for this organisation" do it "shows only stock owners for this organisation" do
expect(page).to have_content(housing_provider.name) expect(page).to have_content(housing_provider.name)
expect(page).not_to have_content(other_org_housing_provider.name) expect(page).not_to have_content(other_org_housing_provider.name)
end end
@ -505,16 +505,16 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
it "shows the pagination count" do it "shows the pagination count" do
expect(page).to have_content("1 total housing providers") expect(page).to have_content("1 total stock owners")
end end
context "when adding a housing provider" do context "when adding a stock owner" do
before do before do
get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {} get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {}
end end
it "has the correct header" do it "has the correct header" do
expect(response.body).to include("What is the name of this organisation&#39;s housing provider?") expect(response.body).to include("What is the name of this organisation&#39;s stock owner?")
end end
it "shows an add button" do it "shows an add button" do
@ -562,7 +562,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(response.body).to include("Remove") expect(response.body).to include("Remove")
end end
context "when adding a housing provider" do context "when adding a stock owner" do
before do before do
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {} get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {}
end end

Loading…
Cancel
Save