From e77c89b46cab0eff4c3b0b45ab25bf9aff7d7d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Thu, 7 Jul 2022 09:37:59 +0100 Subject: [PATCH] CLDC-1128: Scheme organisations renaming (#712) Rename owning and managing organisations for schemes --- app/controllers/locations_controller.rb | 2 +- app/controllers/organisations_controller.rb | 2 +- app/controllers/schemes_controller.rb | 10 ++--- app/models/form/setup/questions/scheme_id.rb | 2 +- app/models/organisation.rb | 4 +- app/models/scheme.rb | 12 +++--- app/views/schemes/_scheme_list.html.erb | 2 +- app/views/schemes/details.html.erb | 16 ++++---- app/views/schemes/new.html.erb | 11 +++-- config/locales/en.yml | 2 +- ...20705130923_rename_scheme_organisations.rb | 8 ++++ db/schema.rb | 14 +++---- spec/factories/scheme.rb | 2 +- spec/features/schemes_spec.rb | 14 +++---- .../form/setup/questions/scheme_id_spec.rb | 6 +-- spec/models/organisation_spec.rb | 2 +- spec/models/scheme_spec.rb | 2 +- spec/requests/locations_controller_spec.rb | 32 +++++++-------- .../requests/organisations_controller_spec.rb | 8 ++-- spec/requests/schemes_controller_spec.rb | 40 +++++++++---------- 20 files changed, 99 insertions(+), 92 deletions(-) create mode 100644 db/migrate/20220705130923_rename_scheme_organisations.rb diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 568a2fa60..d12968cc7 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -54,7 +54,7 @@ private end def authenticate_action! - if %w[new edit update create index].include?(action_name) && !((current_user.organisation == @scheme.organisation) || current_user.support?) + if %w[new edit update create index].include?(action_name) && !((current_user.organisation == @scheme.owning_organisation) || current_user.support?) render_not_found and return end end 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 c6e18db29..c32aabfcb 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -29,7 +29,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 @@ -103,8 +103,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, :id, @@ -116,7 +116,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 @@ -132,7 +132,7 @@ private def authenticate_scope! head :unauthorized and return unless current_user.data_coordinator? || current_user.support? - if %w[show locations primary_client_group confirm_secondary_client_group secondary_client_group support details check_answers].include?(action_name) && !((current_user.organisation == @scheme.organisation) || current_user.support?) + if %w[show locations primary_client_group confirm_secondary_client_group secondary_client_group support details check_answers].include?(action_name) && !((current_user.organisation == @scheme.owning_organisation) || current_user.support?) render_not_found and return end end diff --git a/app/models/form/setup/questions/scheme_id.rb b/app/models/form/setup/questions/scheme_id.rb index b7f296a37..d17cbc806 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/organisation.rb b/app/models/organisation.rb index 65fce7e51..3cae243c2 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -4,8 +4,8 @@ class Organisation < ApplicationRecord has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id" has_many :data_protection_confirmations has_many :organisation_rent_periods - has_many :owned_schemes, class_name: "Scheme", foreign_key: "stock_owning_organisation_id" - has_many :managed_schemes, class_name: "Scheme" + has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id" + has_many :managed_schemes, class_name: "Scheme", foreign_key: "managing_organisation_id" scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by, ->(param) { search_by_name(param) } diff --git a/app/models/scheme.rb b/app/models/scheme.rb index f93c08778..9dc9c62a0 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -1,6 +1,6 @@ class Scheme < ApplicationRecord - belongs_to :organisation - belongs_to :stock_owning_organisation, optional: true, class_name: "Organisation" + belongs_to :owning_organisation, class_name: "Organisation" + belongs_to :managing_organisation, optional: true, class_name: "Organisation" has_many :locations has_many :case_logs @@ -95,8 +95,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 }, ] @@ -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 8b5c6c85c..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.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/app/views/schemes/details.html.erb b/app/views/schemes/details.html.erb index 73ef511aa..d45d14fa9 100644 --- a/app/views/schemes/details.html.erb +++ b/app/views/schemes/details.html.erb @@ -29,25 +29,25 @@ <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% stock_org_answer_options = null_option + organisations %> - <%= f.govuk_collection_select :stock_owning_organisation_id, - stock_org_answer_options, + <%= f.govuk_collection_select :managing_organisation_id, + organisations, :id, :name, - label: { text: "Which organisation owns the housing stock for this scheme?", size: "m" }, + label: { text: "Which organisation manages this scheme?", size: "m" }, + options: { required: true }, "data-controller": %w[accessible-autocomplete conditional-filter] %> <% if current_user.support? %> - <%= f.govuk_collection_select :organisation_id, - organisations, + <%= f.govuk_collection_select :owning_organisation_id, + stock_org_answer_options, :id, :name, - label: { text: "Which organisation manages this scheme?", size: "m" }, - options: { required: true }, + label: { text: "Which organisation owns the housing stock for this scheme?", size: "m" }, "data-controller": %w[accessible-autocomplete conditional-filter] %> <% end %> <% if current_user.data_coordinator? %> - <%= f.hidden_field :organisation_id, value: current_user.organisation.id %> + <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <% end %> <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> diff --git a/app/views/schemes/new.html.erb b/app/views/schemes/new.html.erb index 194f61c3e..f4cbc2827 100644 --- a/app/views/schemes/new.html.erb +++ b/app/views/schemes/new.html.erb @@ -30,24 +30,23 @@ <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% answer_options = null_option + organisations %> - <%= f.govuk_collection_select :stock_owning_organisation_id, + <%= f.govuk_collection_select :managing_organisation_id, answer_options, :id, :name, - label: { text: "Which organisation owns the housing stock for this scheme?", size: "m" }, + label: { text: "Which organisation manages this scheme?", size: "m" }, "data-controller": %w[accessible-autocomplete conditional-filter] %> - <% if current_user.support? %> - <%= f.govuk_collection_select :organisation_id, + <%= f.govuk_collection_select :owning_organisation_id, answer_options, :id, :name, - label: { text: "Which organisation manages this scheme?", size: "m" }, + label: { text: "Which organisation owns the housing stock for this scheme?", size: "m" }, "data-controller": %w[accessible-autocomplete conditional-filter] %> <% end %> <% if current_user.data_coordinator? %> - <%= f.hidden_field :organisation_id, value: current_user.organisation.id %> + <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <% end %> <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> 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/db/migrate/20220705130923_rename_scheme_organisations.rb b/db/migrate/20220705130923_rename_scheme_organisations.rb new file mode 100644 index 000000000..5ea1acebc --- /dev/null +++ b/db/migrate/20220705130923_rename_scheme_organisations.rb @@ -0,0 +1,8 @@ +class RenameSchemeOrganisations < ActiveRecord::Migration[7.0] + def change + change_table :schemes, bulk: true do |t| + t.rename :organisation_id, :owning_organisation_id + t.rename :stock_owning_organisation_id, :managing_organisation_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 62044426f..429738353 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_07_04_135746) do +ActiveRecord::Schema[7.0].define(version: 2022_07_05_130923) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -300,7 +300,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_04_135746) do create_table "schemes", force: :cascade do |t| t.string "service_name" - t.bigint "organisation_id", null: false + t.bigint "owning_organisation_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "primary_client_group" @@ -312,9 +312,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_04_135746) do t.string "intended_stay" t.datetime "end_date" t.integer "has_other_client_group" - t.bigint "stock_owning_organisation_id" - t.index ["organisation_id"], name: "index_schemes_on_organisation_id" - t.index ["stock_owning_organisation_id"], name: "index_schemes_on_stock_owning_organisation_id" + t.bigint "managing_organisation_id" + t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id" + t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id" end create_table "users", force: :cascade do |t| @@ -373,6 +373,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_04_135746) do add_foreign_key "case_logs", "locations" add_foreign_key "case_logs", "schemes" add_foreign_key "locations", "schemes" - add_foreign_key "schemes", "organisations" - add_foreign_key "schemes", "organisations", column: "stock_owning_organisation_id" + add_foreign_key "schemes", "organisations", column: "managing_organisation_id" + add_foreign_key "schemes", "organisations", column: "owning_organisation_id" end diff --git a/spec/factories/scheme.rb b/spec/factories/scheme.rb index 6ed28631b..5317d9e1d 100644 --- a/spec/factories/scheme.rb +++ b/spec/factories/scheme.rb @@ -8,7 +8,7 @@ FactoryBot.define do intended_stay { %w[M P S V X].sample } primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } - organisation + owning_organisation { FactoryBot.create(:organisation) } created_at { Time.zone.now } end end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 98647a193..6408bbf68 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -4,8 +4,8 @@ RSpec.describe "Schemes scheme Features" do context "when viewing list of schemes" do context "when I am signed as a coordinator user and there are schemes in the database" do let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } - let!(:schemes) { FactoryBot.create_list(:scheme, 5, organisation: user.organisation) } - let!(:scheme_to_search) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation) } + let!(:scheme_to_search) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } before do visit("/logs") @@ -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 @@ -652,9 +652,9 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content "Supported housing schemes" expect(page).to have_content scheme.id_to_display expect(page).to have_content scheme.service_name - expect(page).to have_content scheme.organisation.name - expect(page).to have_content scheme.stock_owning_organisation.name - expect(page).to have_content "#{scheme.organisation.name} has been created." + expect(page).to have_content scheme.owning_organisation.name + expect(page).to have_content scheme.managing_organisation.name + expect(page).to have_content "#{scheme.owning_organisation.name} has been created." end end end diff --git a/spec/models/form/setup/questions/scheme_id_spec.rb b/spec/models/form/setup/questions/scheme_id_spec.rb index 2a71fb2a5..c40d5302c 100644 --- a/spec/models/form/setup/questions/scheme_id_spec.rb +++ b/spec/models/form/setup/questions/scheme_id_spec.rb @@ -42,12 +42,12 @@ 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 - FactoryBot.create(:scheme, organisation_id: organisation_2.id) + FactoryBot.create(:scheme, owning_organisation: organisation_2) end it "has the correct answer_options based on the schemes the user's organisation owns or manages" do diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 3addfd76b..fd2088b6d 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Organisation, type: :model do describe "#new" do let(:user) { FactoryBot.create(:user) } let!(:organisation) { user.organisation } - let!(:scheme) { FactoryBot.create(:scheme, organisation:, stock_owning_organisation: organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation, managing_organisation: organisation) } it "has expected fields" do expect(organisation.attribute_names).to include("name", "phone", "provider_type") diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb index 1581bb1e0..96c9b86a7 100644 --- a/spec/models/scheme_spec.rb +++ b/spec/models/scheme_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Scheme, type: :model do let(:scheme) { FactoryBot.create(:scheme) } it "belongs to an organisation" do - expect(scheme.organisation).to be_a(Organisation) + expect(scheme.owning_organisation).to be_a(Organisation) end describe "scopes" do diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 36025a306..cba28a541 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe LocationsController, type: :request do let(:page) { Capybara::Node::Simple.new(response.body) } let(:user) { FactoryBot.create(:user, :support) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } describe "#new" do context "when not signed in" do @@ -29,7 +29,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } before do sign_in user @@ -89,7 +89,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } before do @@ -105,7 +105,7 @@ RSpec.describe LocationsController, type: :request do end it "creates a new location for scheme with valid params" do - expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) + expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.total_units).to eq(5) @@ -151,7 +151,7 @@ RSpec.describe LocationsController, type: :request do end it "creates a new location for scheme with valid params" do - expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) + expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") expect(Location.last.total_units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") @@ -170,7 +170,7 @@ RSpec.describe LocationsController, type: :request do end it "creates a new location for scheme with valid params" do - expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) + expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") expect(Location.last.total_units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") @@ -189,7 +189,7 @@ RSpec.describe LocationsController, type: :request do end it "creates a new location for scheme with valid params" do - expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) + expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") expect(Location.last.total_units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") @@ -322,7 +322,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:location) { FactoryBot.create(:location, scheme:) } before do @@ -348,7 +348,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :support) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:location) { FactoryBot.create(:location, scheme:) } before do @@ -388,7 +388,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:location) { FactoryBot.create(:location, scheme:) } let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } @@ -404,7 +404,7 @@ RSpec.describe LocationsController, type: :request do end it "updates existing location for scheme with valid params" do - expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) + expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.total_units).to eq(5) @@ -450,7 +450,7 @@ RSpec.describe LocationsController, type: :request do end it "updates existing location for scheme with valid params" do - expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) + expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") expect(Location.last.total_units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") @@ -468,7 +468,7 @@ RSpec.describe LocationsController, type: :request do end it "updates existing location for scheme with valid params" do - expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) + expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") expect(Location.last.total_units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") @@ -486,7 +486,7 @@ RSpec.describe LocationsController, type: :request do end it "updates existing location for scheme with valid params" do - expect(Location.last.scheme.organisation_id).to eq(user.organisation_id) + expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") expect(Location.last.total_units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") @@ -497,7 +497,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a support user" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:location) { FactoryBot.create(:location, scheme:) } let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } @@ -615,7 +615,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator user" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) } 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 2c2238f34..a9a99ce00 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -203,7 +203,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator user" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:specific_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:specific_scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } before do sign_in user @@ -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) @@ -352,7 +352,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") @@ -370,7 +370,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", organisation_id: organisation.id } } } + let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No", owning_organisation_id: organisation.id } } } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -386,7 +386,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") @@ -401,12 +401,12 @@ RSpec.describe SchemesController, type: :request do end context "when required organisation id param is missing" do - let(:params) { { "scheme" => { "service_name" => "qweqwer", "sensitive" => "Yes", "organisation_id" => "", "scheme_type" => "Foyer", "registered_under_care_act" => "Yes – part registered as a care home" } } } + let(:params) { { "scheme" => { "service_name" => "qweqwer", "sensitive" => "Yes", "owning_organisation_id" => "", "scheme_type" => "Foyer", "registered_under_care_act" => "Yes – part registered as a care home" } } } 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 @@ -436,7 +436,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let(:scheme_to_update) { FactoryBot.create(:scheme, organisation: user.organisation) } + let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } before do sign_in user @@ -619,7 +619,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a support" do let(:user) { FactoryBot.create(:user, :support) } - let(:scheme_to_update) { FactoryBot.create(:scheme, organisation: user.organisation) } + let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) @@ -772,8 +772,8 @@ RSpec.describe SchemesController, type: :request do scheme_type: "Foyer", registered_under_care_act: "No", 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 @@ -788,8 +788,8 @@ RSpec.describe SchemesController, type: :request do expect(scheme_to_update.reload.scheme_type).to eq("Foyer") 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.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 @@ -837,7 +837,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -903,7 +903,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -969,7 +969,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -1035,7 +1035,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -1101,7 +1101,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do @@ -1167,7 +1167,7 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:another_scheme) { FactoryBot.create(:scheme) } before do