Browse Source

CLDC-1128: Scheme organisations renaming (#712)

Rename owning and managing organisations for schemes
pull/715/head
Stéphane Meny 3 years ago committed by GitHub
parent
commit
e77c89b46c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/locations_controller.rb
  2. 2
      app/controllers/organisations_controller.rb
  3. 10
      app/controllers/schemes_controller.rb
  4. 2
      app/models/form/setup/questions/scheme_id.rb
  5. 4
      app/models/organisation.rb
  6. 12
      app/models/scheme.rb
  7. 2
      app/views/schemes/_scheme_list.html.erb
  8. 16
      app/views/schemes/details.html.erb
  9. 11
      app/views/schemes/new.html.erb
  10. 2
      config/locales/en.yml
  11. 8
      db/migrate/20220705130923_rename_scheme_organisations.rb
  12. 14
      db/schema.rb
  13. 2
      spec/factories/scheme.rb
  14. 14
      spec/features/schemes_spec.rb
  15. 6
      spec/models/form/setup/questions/scheme_id_spec.rb
  16. 2
      spec/models/organisation_spec.rb
  17. 2
      spec/models/scheme_spec.rb
  18. 32
      spec/requests/locations_controller_spec.rb
  19. 8
      spec/requests/organisations_controller_spec.rb
  20. 40
      spec/requests/schemes_controller_spec.rb

2
app/controllers/locations_controller.rb

@ -54,7 +54,7 @@ private
end end
def authenticate_action! 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 render_not_found and return
end end
end end

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

10
app/controllers/schemes_controller.rb

@ -29,7 +29,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
@ -103,8 +103,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,
:id, :id,
@ -116,7 +116,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
@ -132,7 +132,7 @@ private
def authenticate_scope! def authenticate_scope!
head :unauthorized and return unless current_user.data_coordinator? || current_user.support? 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 render_not_found and return
end end
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/organisation.rb

@ -4,8 +4,8 @@ class Organisation < ApplicationRecord
has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id" has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id"
has_many :data_protection_confirmations has_many :data_protection_confirmations
has_many :organisation_rent_periods has_many :organisation_rent_periods
has_many :owned_schemes, class_name: "Scheme", foreign_key: "stock_owning_organisation_id" has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id"
has_many :managed_schemes, class_name: "Scheme" has_many :managed_schemes, class_name: "Scheme", foreign_key: "managing_organisation_id"
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param) } scope :search_by, ->(param) { search_by_name(param) }

12
app/models/scheme.rb

@ -1,6 +1,6 @@
class Scheme < ApplicationRecord class Scheme < ApplicationRecord
belongs_to :organisation belongs_to :owning_organisation, class_name: "Organisation"
belongs_to :stock_owning_organisation, optional: true, class_name: "Organisation" belongs_to :managing_organisation, optional: true, class_name: "Organisation"
has_many :locations has_many :locations
has_many :case_logs has_many :case_logs
@ -95,8 +95,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 },
] ]
@ -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.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 %>

16
app/views/schemes/details.html.erb

@ -29,25 +29,25 @@
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% stock_org_answer_options = null_option + organisations %> <% stock_org_answer_options = null_option + organisations %>
<%= f.govuk_collection_select :stock_owning_organisation_id, <%= f.govuk_collection_select :managing_organisation_id,
stock_org_answer_options, organisations,
:id, :id,
:name, :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] %> "data-controller": %w[accessible-autocomplete conditional-filter] %>
<% if current_user.support? %> <% if current_user.support? %>
<%= f.govuk_collection_select :organisation_id, <%= f.govuk_collection_select :owning_organisation_id,
organisations, stock_org_answer_options,
:id, :id,
:name, :name,
label: { text: "Which organisation manages this scheme?", size: "m" }, label: { text: "Which organisation owns the housing stock for this scheme?", size: "m" },
options: { required: true },
"data-controller": %w[accessible-autocomplete conditional-filter] %> "data-controller": %w[accessible-autocomplete conditional-filter] %>
<% end %> <% end %>
<% if current_user.data_coordinator? %> <% 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 %> <% end %>
<% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>

11
app/views/schemes/new.html.erb

@ -30,24 +30,23 @@
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% answer_options = null_option + organisations %> <% answer_options = null_option + organisations %>
<%= f.govuk_collection_select :stock_owning_organisation_id, <%= f.govuk_collection_select :managing_organisation_id,
answer_options, answer_options,
:id, :id,
:name, :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] %> "data-controller": %w[accessible-autocomplete conditional-filter] %>
<% if current_user.support? %> <% if current_user.support? %>
<%= f.govuk_collection_select :organisation_id, <%= f.govuk_collection_select :owning_organisation_id,
answer_options, answer_options,
:id, :id,
:name, :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] %> "data-controller": %w[accessible-autocomplete conditional-filter] %>
<% end %> <% end %>
<% if current_user.data_coordinator? %> <% 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 %> <% end %>
<% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> <% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>

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:

8
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

14
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" 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| create_table "schemes", force: :cascade do |t|
t.string "service_name" 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 "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "primary_client_group" 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.string "intended_stay"
t.datetime "end_date" t.datetime "end_date"
t.integer "has_other_client_group" t.integer "has_other_client_group"
t.bigint "stock_owning_organisation_id" t.bigint "managing_organisation_id"
t.index ["organisation_id"], name: "index_schemes_on_organisation_id" t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id"
t.index ["stock_owning_organisation_id"], name: "index_schemes_on_stock_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id"
end end
create_table "users", force: :cascade do |t| 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", "locations"
add_foreign_key "case_logs", "schemes" add_foreign_key "case_logs", "schemes"
add_foreign_key "locations", "schemes" add_foreign_key "locations", "schemes"
add_foreign_key "schemes", "organisations" add_foreign_key "schemes", "organisations", column: "managing_organisation_id"
add_foreign_key "schemes", "organisations", column: "stock_owning_organisation_id" add_foreign_key "schemes", "organisations", column: "owning_organisation_id"
end end

2
spec/factories/scheme.rb

@ -8,7 +8,7 @@ FactoryBot.define do
intended_stay { %w[M P S V X].sample } 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 } 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 } 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 } created_at { Time.zone.now }
end end
end end

14
spec/features/schemes_spec.rb

@ -4,8 +4,8 @@ RSpec.describe "Schemes scheme Features" do
context "when viewing list of schemes" 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 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!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) }
let!(:schemes) { FactoryBot.create_list(:scheme, 5, organisation: user.organisation) } let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation) }
let!(:scheme_to_search) { FactoryBot.create(:scheme, organisation: user.organisation) } let!(:scheme_to_search) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
before do before do
visit("/logs") visit("/logs")
@ -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
@ -652,9 +652,9 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "Supported housing schemes" expect(page).to have_content "Supported housing schemes"
expect(page).to have_content scheme.id_to_display expect(page).to have_content scheme.id_to_display
expect(page).to have_content scheme.service_name expect(page).to have_content scheme.service_name
expect(page).to have_content scheme.organisation.name expect(page).to have_content scheme.owning_organisation.name
expect(page).to have_content scheme.stock_owning_organisation.name expect(page).to have_content scheme.managing_organisation.name
expect(page).to have_content "#{scheme.organisation.name} has been created." expect(page).to have_content "#{scheme.owning_organisation.name} has been created."
end end
end end
end end

6
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 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
FactoryBot.create(:scheme, organisation_id: organisation_2.id) FactoryBot.create(:scheme, owning_organisation: organisation_2)
end end
it "has the correct answer_options based on the schemes the user's organisation owns or manages" do it "has the correct answer_options based on the schemes the user's organisation owns or manages" do

2
spec/models/organisation_spec.rb

@ -4,7 +4,7 @@ RSpec.describe Organisation, type: :model do
describe "#new" do describe "#new" do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let!(:organisation) { user.organisation } 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 it "has expected fields" do
expect(organisation.attribute_names).to include("name", "phone", "provider_type") expect(organisation.attribute_names).to include("name", "phone", "provider_type")

2
spec/models/scheme_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Scheme, type: :model do
let(:scheme) { FactoryBot.create(:scheme) } let(:scheme) { FactoryBot.create(:scheme) }
it "belongs to an organisation" do it "belongs to an organisation" do
expect(scheme.organisation).to be_a(Organisation) expect(scheme.owning_organisation).to be_a(Organisation)
end end
describe "scopes" do describe "scopes" do

32
spec/requests/locations_controller_spec.rb

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe LocationsController, type: :request do RSpec.describe LocationsController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { FactoryBot.create(:user, :support) } 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 describe "#new" do
context "when not signed in" 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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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 before do
sign_in user sign_in user
@ -89,7 +89,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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" } } } let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } }
before do before do
@ -105,7 +105,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "creates a new location for scheme with valid params" do 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.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
expect(Location.last.total_units).to eq(5) expect(Location.last.total_units).to eq(5)
@ -151,7 +151,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "creates a new location for scheme with valid params" do 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.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.total_units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
@ -170,7 +170,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "creates a new location for scheme with valid params" do 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.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.total_units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
@ -189,7 +189,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "creates a new location for scheme with valid params" do 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.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.total_units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") 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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
@ -348,7 +348,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } 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:) } let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
@ -388,7 +388,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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!(: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" } } } 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 end
it "updates existing location for scheme with valid params" do 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.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
expect(Location.last.total_units).to eq(5) expect(Location.last.total_units).to eq(5)
@ -450,7 +450,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "updates existing location for scheme with valid params" do 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.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.total_units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
@ -468,7 +468,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "updates existing location for scheme with valid params" do 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.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.total_units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
@ -486,7 +486,7 @@ RSpec.describe LocationsController, type: :request do
end end
it "updates existing location for scheme with valid params" do 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.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.total_units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") 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 context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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!(: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" } } } 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 context "when signed in as a data coordinator user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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:) } let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) }
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

40
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 context "when signed in as a data coordinator user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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 before do
sign_in user sign_in user
@ -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)
@ -352,7 +352,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")
@ -370,7 +370,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", 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 before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) 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 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")
@ -401,12 +401,12 @@ RSpec.describe SchemesController, type: :request do
end end
context "when required organisation id param is missing" do 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 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
@ -436,7 +436,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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 before do
sign_in user sign_in user
@ -619,7 +619,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support" do context "when signed in as a support" do
let(:user) { FactoryBot.create(:user, :support) } 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 before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -772,8 +772,8 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "Foyer", scheme_type: "Foyer",
registered_under_care_act: "No", registered_under_care_act: "No",
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
@ -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.scheme_type).to eq("Foyer")
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.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
@ -837,7 +837,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -903,7 +903,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -969,7 +969,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -1035,7 +1035,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -1101,7 +1101,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do
@ -1167,7 +1167,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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) } let!(:another_scheme) { FactoryBot.create(:scheme) }
before do before do

Loading…
Cancel
Save