diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 4721a31ed..907b0fddc 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -17,7 +17,7 @@ class OrganisationsController < ApplicationController end def schemes - all_schemes = Scheme.where(organisation: @organisation) + all_schemes = Scheme.where(owning_organisation: @organisation) @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term)) @searched = search_term.presence diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 68817507c..2e152b5eb 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -35,7 +35,7 @@ class SchemesController < ApplicationController if @scheme.save render "schemes/primary_client_group" else - @scheme.errors.add(:organisation_id, message: @scheme.errors[:organisation]) + @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) @scheme.errors.delete(:organisation) render :new, status: :unprocessable_entity end @@ -109,8 +109,8 @@ private def scheme_params required_params = params.require(:scheme).permit(:service_name, :sensitive, - :organisation_id, - :stock_owning_organisation_id, + :owning_organisation_id, + :managing_organisation_id, :scheme_type, :registered_under_care_act, :total_units, @@ -123,7 +123,7 @@ private required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] if current_user.data_coordinator? - required_params[:organisation_id] = current_user.organisation_id + required_params[:owning_organisation_id] = current_user.organisation_id end required_params end diff --git a/app/models/form/setup/questions/scheme_id.rb b/app/models/form/setup/questions/scheme_id.rb index d1ba79dcd..c4b5e618e 100644 --- a/app/models/form/setup/questions/scheme_id.rb +++ b/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) 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| user_org_scheme_ids.include?(k.to_i) end diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 93c0c1e9c..9dc9c62a0 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -132,8 +132,8 @@ class Scheme < ApplicationRecord { name: "Service code", value: id_to_display }, { name: "Name", value: service_name }, { name: "Confidential information", value: sensitive }, - { name: "Housing stock owned by", value: stock_owning_organisation&.name }, - { name: "Managed by", value: organisation.name }, + { name: "Housing stock owned by", value: owning_organisation.name }, + { name: "Managed by", value: managing_organisation&.name }, { name: "Type of scheme", value: scheme_type }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act }, { name: "Primary client group", value: primary_client_group }, diff --git a/app/views/schemes/_scheme_list.html.erb b/app/views/schemes/_scheme_list.html.erb index 547afe9f3..e12eef11a 100644 --- a/app/views/schemes/_scheme_list.html.erb +++ b/app/views/schemes/_scheme_list.html.erb @@ -24,7 +24,7 @@ <%= body.row do |row| %> <% 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: scheme.managing_organisation.name) %> + <% row.cell(text: scheme.managing_organisation&.name) %> <% row.cell(text: scheme.created_at.to_formatted_s(:govuk_date)) %> <% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 421060f1e..0c8fc4695 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -43,7 +43,7 @@ en: models: scheme: attributes: - organisation: + owning_organisation: required: "Enter the existing organisation’s name" validations: diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 2c29413bf..da644df4f 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -253,8 +253,8 @@ RSpec.describe "Schemes scheme Features" do check "This scheme contains confidential information" choose "Direct access hostel" choose "Yes – registered care home providing nursing care" - select organisation.name, from: "scheme-organisation-id-field" - select organisation.name, from: "scheme-stock-owning-organisation-id-field" + select organisation.name, from: "scheme-managing-organisation-id-field" + select organisation.name, from: "scheme-owning-organisation-id-field" click_button "Save and continue" end diff --git a/spec/models/form/setup/questions/scheme_id_spec.rb b/spec/models/form/setup/questions/scheme_id_spec.rb index e319dd5ae..c40d5302c 100644 --- a/spec/models/form/setup/questions/scheme_id_spec.rb +++ b/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 let(:organisation) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) } - let(:user) { FactoryBot.create(:user, organisation_id: organisation.id) } - let(:scheme) { FactoryBot.create(:scheme, organisation_id: organisation.id) } + let(:user) { FactoryBot.create(:user, organisation:) } + let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation) } let(:case_log) { FactoryBot.create(:case_log, created_by: user) } before do diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index d8a756734..357dbb4ba 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -43,7 +43,7 @@ RSpec.describe OrganisationsController, type: :request do context "when support user" do let(:user) { FactoryBot.create(:user, :support) } 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 allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -72,7 +72,7 @@ RSpec.describe OrganisationsController, type: :request do end 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 } before do @@ -101,7 +101,7 @@ RSpec.describe OrganisationsController, type: :request do context "when data coordinator user" do let(:user) { FactoryBot.create(:user, :data_coordinator) } 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 sign_in user @@ -141,7 +141,7 @@ RSpec.describe OrganisationsController, type: :request do end 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 } before do diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 0160db535..782123144 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -213,7 +213,7 @@ RSpec.describe SchemesController, type: :request do get "/schemes/#{specific_scheme.id}" 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.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.id_to_display) expect(page).to have_content(specific_scheme.service_name) @@ -246,7 +246,7 @@ RSpec.describe SchemesController, type: :request do it "has page heading" do 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.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.id_to_display) 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 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.scheme_type).to eq("Foyer") 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 let(:organisation) { FactoryBot.create(:organisation) } 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 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 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.scheme_type).to eq("Foyer") 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 post "/schemes", params: params 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 @@ -974,8 +974,8 @@ RSpec.describe SchemesController, type: :request do registered_under_care_act: "No", total_units: "1", page: "details", - organisation_id: another_organisation.id, - stock_owning_organisation_id: another_organisation.id } } + owning_organisation_id: another_organisation.id, + managing_organisation_id: another_organisation.id } } end 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.registered_under_care_act).to eq("No") 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.stock_owning_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.managing_organisation_id).to eq(another_organisation.id) end context "when updating from check answers page" do