Browse Source

Clear up issues with owning and managing organisations for schemes

pull/712/head
Stéphane Meny 3 years ago
parent
commit
92c4ef05fb
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 2
      app/controllers/organisations_controller.rb
  2. 8
      app/controllers/schemes_controller.rb
  3. 2
      app/models/form/setup/questions/scheme_id.rb
  4. 4
      app/models/scheme.rb
  5. 2
      app/views/schemes/_scheme_list.html.erb
  6. 2
      config/locales/en.yml
  7. 4
      spec/features/schemes_spec.rb
  8. 4
      spec/models/form/setup/questions/scheme_id_spec.rb
  9. 8
      spec/requests/organisations_controller_spec.rb
  10. 20
      spec/requests/schemes_controller_spec.rb

2
app/controllers/organisations_controller.rb

@ -17,7 +17,7 @@ class OrganisationsController < ApplicationController
end end
def schemes def schemes
all_schemes = Scheme.where(organisation: @organisation) all_schemes = Scheme.where(owning_organisation: @organisation)
@pagy, @schemes = pagy(filtered_collection(all_schemes, search_term)) @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term))
@searched = search_term.presence @searched = search_term.presence

8
app/controllers/schemes_controller.rb

@ -35,7 +35,7 @@ class SchemesController < ApplicationController
if @scheme.save if @scheme.save
render "schemes/primary_client_group" render "schemes/primary_client_group"
else else
@scheme.errors.add(:organisation_id, message: @scheme.errors[:organisation]) @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation])
@scheme.errors.delete(:organisation) @scheme.errors.delete(:organisation)
render :new, status: :unprocessable_entity render :new, status: :unprocessable_entity
end end
@ -109,8 +109,8 @@ private
def scheme_params def scheme_params
required_params = params.require(:scheme).permit(:service_name, required_params = params.require(:scheme).permit(:service_name,
:sensitive, :sensitive,
:organisation_id, :owning_organisation_id,
:stock_owning_organisation_id, :managing_organisation_id,
:scheme_type, :scheme_type,
:registered_under_care_act, :registered_under_care_act,
:total_units, :total_units,
@ -123,7 +123,7 @@ private
required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
if current_user.data_coordinator? if current_user.data_coordinator?
required_params[:organisation_id] = current_user.organisation_id required_params[:owning_organisation_id] = current_user.organisation_id
end end
required_params required_params
end end

2
app/models/form/setup/questions/scheme_id.rb

@ -22,7 +22,7 @@ class Form::Setup::Questions::SchemeId < ::Form::Question
def displayed_answer_options(case_log) def displayed_answer_options(case_log)
return {} unless case_log.created_by return {} unless case_log.created_by
user_org_scheme_ids = Scheme.select(:id).where(organisation_id: case_log.created_by.organisation_id).map(&:id) user_org_scheme_ids = Scheme.select(:id).where(owning_organisation_id: case_log.created_by.organisation_id).map(&:id)
answer_options.select do |k, _v| answer_options.select do |k, _v|
user_org_scheme_ids.include?(k.to_i) user_org_scheme_ids.include?(k.to_i)
end end

4
app/models/scheme.rb

@ -132,8 +132,8 @@ class Scheme < ApplicationRecord
{ name: "Service code", value: id_to_display }, { name: "Service code", value: id_to_display },
{ name: "Name", value: service_name }, { name: "Name", value: service_name },
{ name: "Confidential information", value: sensitive }, { name: "Confidential information", value: sensitive },
{ name: "Housing stock owned by", value: stock_owning_organisation&.name }, { name: "Housing stock owned by", value: owning_organisation.name },
{ name: "Managed by", value: organisation.name }, { name: "Managed by", value: managing_organisation&.name },
{ name: "Type of scheme", value: scheme_type }, { name: "Type of scheme", value: scheme_type },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act },
{ name: "Primary client group", value: primary_client_group }, { name: "Primary client group", value: primary_client_group },

2
app/views/schemes/_scheme_list.html.erb

@ -24,7 +24,7 @@
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: scheme.id_to_display) %> <% row.cell(text: scheme.id_to_display) %>
<% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: scheme.managing_organisation.name) %> <% row.cell(text: scheme.managing_organisation&.name) %>
<% row.cell(text: scheme.created_at.to_formatted_s(:govuk_date)) %> <% row.cell(text: scheme.created_at.to_formatted_s(:govuk_date)) %>
<% end %> <% end %>
<% end %> <% end %>

2
config/locales/en.yml

@ -43,7 +43,7 @@ en:
models: models:
scheme: scheme:
attributes: attributes:
organisation: owning_organisation:
required: "Enter the existing organisation’s name" required: "Enter the existing organisation’s name"
validations: validations:

4
spec/features/schemes_spec.rb

@ -253,8 +253,8 @@ RSpec.describe "Schemes scheme Features" do
check "This scheme contains confidential information" check "This scheme contains confidential information"
choose "Direct access hostel" choose "Direct access hostel"
choose "Yes – registered care home providing nursing care" choose "Yes – registered care home providing nursing care"
select organisation.name, from: "scheme-organisation-id-field" select organisation.name, from: "scheme-managing-organisation-id-field"
select organisation.name, from: "scheme-stock-owning-organisation-id-field" select organisation.name, from: "scheme-owning-organisation-id-field"
click_button "Save and continue" click_button "Save and continue"
end end

4
spec/models/form/setup/questions/scheme_id_spec.rb

@ -42,8 +42,8 @@ RSpec.describe Form::Setup::Questions::SchemeId, type: :model do
context "when a user is signed in" do context "when a user is signed in" do
let(:organisation) { FactoryBot.create(:organisation) } let(:organisation) { FactoryBot.create(:organisation) }
let(:organisation_2) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.create(:user, organisation_id: organisation.id) } let(:user) { FactoryBot.create(:user, organisation:) }
let(:scheme) { FactoryBot.create(:scheme, organisation_id: organisation.id) } let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation) }
let(:case_log) { FactoryBot.create(:case_log, created_by: user) } let(:case_log) { FactoryBot.create(:case_log, created_by: user) }
before do before do

8
spec/requests/organisations_controller_spec.rb

@ -43,7 +43,7 @@ RSpec.describe OrganisationsController, type: :request do
context "when support user" do context "when support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:schemes) { FactoryBot.create_list(:scheme, 5) } let!(:schemes) { FactoryBot.create_list(:scheme, 5) }
let!(:same_org_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } let!(:same_org_scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -72,7 +72,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when searching" do context "when searching" do
let!(:searched_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } let!(:searched_scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:search_param) { searched_scheme.id } let(:search_param) { searched_scheme.id }
before do before do
@ -101,7 +101,7 @@ RSpec.describe OrganisationsController, type: :request do
context "when data coordinator user" do context "when data coordinator user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:schemes) { FactoryBot.create_list(:scheme, 5) } let!(:schemes) { FactoryBot.create_list(:scheme, 5) }
let!(:same_org_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } let!(:same_org_scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
before do before do
sign_in user sign_in user
@ -141,7 +141,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when searching" do context "when searching" do
let!(:searched_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } let!(:searched_scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:search_param) { searched_scheme.id_to_display } let(:search_param) { searched_scheme.id_to_display }
before do before do

20
spec/requests/schemes_controller_spec.rb

@ -213,7 +213,7 @@ RSpec.describe SchemesController, type: :request do
get "/schemes/#{specific_scheme.id}" get "/schemes/#{specific_scheme.id}"
expect(page).to have_content(specific_scheme.id_to_display) expect(page).to have_content(specific_scheme.id_to_display)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
expect(page).to have_content(specific_scheme.organisation.name) expect(page).to have_content(specific_scheme.owning_organisation.name)
expect(page).to have_content(specific_scheme.sensitive) expect(page).to have_content(specific_scheme.sensitive)
expect(page).to have_content(specific_scheme.id_to_display) expect(page).to have_content(specific_scheme.id_to_display)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
@ -246,7 +246,7 @@ RSpec.describe SchemesController, type: :request do
it "has page heading" do it "has page heading" do
expect(page).to have_content(specific_scheme.id_to_display) expect(page).to have_content(specific_scheme.id_to_display)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
expect(page).to have_content(specific_scheme.organisation.name) expect(page).to have_content(specific_scheme.owning_organisation.name)
expect(page).to have_content(specific_scheme.sensitive) expect(page).to have_content(specific_scheme.sensitive)
expect(page).to have_content(specific_scheme.id_to_display) expect(page).to have_content(specific_scheme.id_to_display)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
@ -551,7 +551,7 @@ RSpec.describe SchemesController, type: :request do
it "creates a new scheme for user organisation with valid params" do it "creates a new scheme for user organisation with valid params" do
post "/schemes", params: params post "/schemes", params: params
expect(Scheme.last.organisation_id).to eq(user.organisation_id) expect(Scheme.last.owning_organisation_id).to eq(user.organisation_id)
expect(Scheme.last.service_name).to eq("testy") expect(Scheme.last.service_name).to eq("testy")
expect(Scheme.last.scheme_type).to eq("Foyer") expect(Scheme.last.scheme_type).to eq("Foyer")
expect(Scheme.last.sensitive).to eq("Yes") expect(Scheme.last.sensitive).to eq("Yes")
@ -569,7 +569,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:organisation) { FactoryBot.create(:organisation) } let(:organisation) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No", total_units: "1", organisation_id: organisation.id } } } let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No", total_units: "1", owning_organisation_id: organisation.id } } }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -585,7 +585,7 @@ RSpec.describe SchemesController, type: :request do
it "creates a new scheme for user organisation with valid params" do it "creates a new scheme for user organisation with valid params" do
post "/schemes", params: params post "/schemes", params: params
expect(Scheme.last.organisation_id).to eq(organisation.id) expect(Scheme.last.owning_organisation_id).to eq(organisation.id)
expect(Scheme.last.service_name).to eq("testy") expect(Scheme.last.service_name).to eq("testy")
expect(Scheme.last.scheme_type).to eq("Foyer") expect(Scheme.last.scheme_type).to eq("Foyer")
expect(Scheme.last.sensitive).to eq("Yes") expect(Scheme.last.sensitive).to eq("Yes")
@ -605,7 +605,7 @@ RSpec.describe SchemesController, type: :request do
it "displays the new page with an error message" do it "displays the new page with an error message" do
post "/schemes", params: params post "/schemes", params: params
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.organisation.required")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation.required"))
end end
end end
end end
@ -974,8 +974,8 @@ RSpec.describe SchemesController, type: :request do
registered_under_care_act: "No", registered_under_care_act: "No",
total_units: "1", total_units: "1",
page: "details", page: "details",
organisation_id: another_organisation.id, owning_organisation_id: another_organisation.id,
stock_owning_organisation_id: another_organisation.id } } managing_organisation_id: another_organisation.id } }
end end
it "renders confirm secondary group after successful update" do it "renders confirm secondary group after successful update" do
@ -991,8 +991,8 @@ RSpec.describe SchemesController, type: :request do
expect(scheme_to_update.reload.sensitive).to eq("Yes") expect(scheme_to_update.reload.sensitive).to eq("Yes")
expect(scheme_to_update.reload.registered_under_care_act).to eq("No") expect(scheme_to_update.reload.registered_under_care_act).to eq("No")
expect(scheme_to_update.reload.total_units).to eq(1) expect(scheme_to_update.reload.total_units).to eq(1)
expect(scheme_to_update.reload.organisation_id).to eq(another_organisation.id) expect(scheme_to_update.reload.owning_organisation_id).to eq(another_organisation.id)
expect(scheme_to_update.reload.stock_owning_organisation_id).to eq(another_organisation.id) expect(scheme_to_update.reload.managing_organisation_id).to eq(another_organisation.id)
end end
context "when updating from check answers page" do context "when updating from check answers page" do

Loading…
Cancel
Save