Browse Source

CLDC-2481: Add ability to disable organisations

pull/2293/head
Robert Sullivan 2 years ago committed by Kat
parent
commit
56203484e4
  1. 10
      app/controllers/organisations_controller.rb
  2. 2
      app/models/form/lettings/questions/stock_owner.rb
  3. 4
      app/views/organisations/toggle_active.html.erb
  4. 8
      db/migrate/20240305112507_add_default_value_to_organisation_active_field.rb
  5. 15
      spec/models/form/lettings/questions/managing_organisation_spec.rb
  6. 26
      spec/models/form/lettings/questions/stock_owner_spec.rb
  7. 7
      spec/models/form/sales/questions/managing_organisation_spec.rb
  8. 20
      spec/models/form/sales/questions/owning_organisation_id_spec.rb
  9. 5
      spec/models/location_spec.rb
  10. 41
      spec/models/organisation_spec.rb
  11. 5
      spec/models/scheme_spec.rb
  12. 40
      spec/policies/organisation_policy_spec.rb
  13. 28
      spec/requests/organisation_relationships_controller_spec.rb
  14. 112
      spec/views/locations/show.html.erb_spec.rb
  15. 14
      spec/views/organisations/show.html.erb_spec.rb
  16. 34
      spec/views/schemes/show.html.erb_spec.rb

10
app/controllers/organisations_controller.rb

@ -109,19 +109,21 @@ class OrganisationsController < ApplicationController
def update
if (current_user.data_coordinator? && org_params[:active].nil?) || current_user.support?
if @organisation.update(org_params)
if org_params[:active] == "false"
case org_params[:active]
when "false"
@organisation.users.filter_by_active
.update_all(
active: false,
confirmed_at: nil,
sign_in_count: 0,
initial_confirmation_sent: false,
reactivate_with_organisation: true)
reactivate_with_organisation: true,
)
flash[:notice] = I18n.t("organisation.deactivated", organisation: @organisation.name)
elsif org_params[:active] == "true"
when "true"
users_to_reactivate = @organisation.users.where(reactivate_with_organisation: true)
users_to_reactivate.each do |user|
user.update(active: true, reactivate_with_organisation: false)
user.update!(active: true, reactivate_with_organisation: false)
user.send_confirmation_instructions
end
flash[:notice] = I18n.t("organisation.reactivated", organisation: @organisation.name)

2
app/models/form/lettings/questions/stock_owner.rb

@ -40,7 +40,7 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question
end
end
else
user.organisation.stock_owners.each do |stock_owner|
user.organisation.stock_owners.filter_by_active.each do |stock_owner|
answer_opts[stock_owner.id] = stock_owner.name
end
recently_absorbed_organisations.each do |absorbed_org|

4
app/views/organisations/toggle_active.html.erb

@ -20,6 +20,10 @@
<%= f.hidden_field :active, value: active_value %>
<%= f.govuk_submit "#{action.capitalize} this organisation" %>
<p class="govuk-body">
<%= govuk_link_to("Cancel", organisation_path(@organisation)) %>
</p>
</div>
</div>
<% end %>

8
db/migrate/20240305112507_add_default_value_to_organisation_active_field.rb

@ -1,8 +1,12 @@
class AddDefaultValueToOrganisationActiveField < ActiveRecord::Migration[7.0]
def change
change_column :organisations, :active, :boolean, :default => true
def up
change_column :organisations, :active, :boolean, default: true
execute "UPDATE organisations
SET active = true;"
end
def down
change_column :organisations, :active, :boolean
end
end

15
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -57,6 +57,7 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
let(:managing_org1) { create(:organisation, name: "Managing org 1") }
let(:managing_org2) { create(:organisation, name: "Managing org 2") }
let(:managing_org3) { create(:organisation, name: "Managing org 3") }
let(:inactive_managing_org) { create(:organisation, name: "Inactive managing org", active: false) }
let(:log) { create(:lettings_log, managing_organisation: managing_org1) }
let!(:org_rel1) do
@ -76,7 +77,9 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
}
end
it "shows current managing agent at top, followed by user's org (with hint), followed by the managing agents of the user's org" do
it "shows current managing agent at top, followed by user's org (with hint), followed by the active managing agents of the user's org" do
create(:organisation_relationship, parent_organisation: user.organisation, child_organisation: inactive_managing_org)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
@ -100,6 +103,10 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: managing_org3)
end
before do
create(:organisation, name: "Inactive managing org", active: false)
end
context "when org owns stock" do
let(:options) do
{
@ -111,7 +118,7 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
}
end
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the managing agents of the current owning organisation" do
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the active managing agents of the current owning organisation" do
log_owning_org.update!(holds_own_stock: true)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
@ -133,7 +140,7 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
org_rel2.child_organisation.update!(merge_date: Time.zone.local(2023, 8, 2), absorbing_organisation_id: log_owning_org.id)
end
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the managing agents of the current owning organisation" do
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the active managing agents of the current owning organisation" do
log_owning_org.update!(holds_own_stock: true)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
@ -149,7 +156,7 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
}
end
it "shows current managing agent at top, followed by the managing agents of the current owning organisation" do
it "shows current managing agent at top, followed by the active managing agents of the current owning organisation" do
log_owning_org.update!(holds_own_stock: false)
expect(question.displayed_answer_options(log, user)).to eq(options)
end

26
spec/models/form/lettings/questions/stock_owner_spec.rb

@ -46,6 +46,7 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
let(:owning_org_1) { create(:organisation, name: "Owning org 1") }
let(:owning_org_2) { create(:organisation, name: "Owning org 2") }
let(:inactive_owning_org) { create(:organisation, name: "Inactive owning org", active: false) }
let!(:org_rel) do
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: owning_org_2)
end
@ -61,7 +62,8 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
}
end
it "shows current stock owner at top, followed by user's org (with hint), followed by the stock owners of the user's org" do
it "shows current stock owner at top, followed by user's org (with hint), followed by the active stock owners of the user's org" do
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: inactive_owning_org)
user.organisation.update!(holds_own_stock: true)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
@ -93,7 +95,8 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
}
end
it "shows current stock owner at top, followed by the stock owners of the user's org" do
it "shows current stock owner at top, followed by the active stock active owners of the user's org" do
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: inactive_owning_org)
user.organisation.update!(holds_own_stock: false)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
@ -203,21 +206,26 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
end
context "when user is support" do
let(:user) { create(:user, :support) }
user = nil
log = nil
before do
user = create(:user, :support)
log = create(:lettings_log)
end
let(:log) { create(:lettings_log) }
it "shows active orgs where organisation holds own stock" do
non_stock_organisation = create(:organisation, name: "Non-stockholding org", holds_own_stock: false)
inactive_organisation = create(:organisation, name: "Inactive org", active: false)
let(:non_stock_organisation) { create(:organisation, holds_own_stock: false) }
let(:expected_opts) do
Organisation.where(holds_own_stock: true).each_with_object(options) do |organisation, hsh|
expected_opts = Organisation.filter_by_active.where(holds_own_stock: true).each_with_object(options) do |organisation, hsh|
hsh[organisation.id] = organisation.name
hsh
end
end
it "shows orgs where organisation holds own stock" do
expect(question.displayed_answer_options(log, user)).to eq(expected_opts)
expect(question.displayed_answer_options(log, user)).not_to include(non_stock_organisation.id)
expect(question.displayed_answer_options(log, user)).not_to include(inactive_organisation.id)
end
context "and org has recently absorbed other orgs and does not have available from date" do

7
spec/models/form/sales/questions/managing_organisation_spec.rb

@ -57,6 +57,7 @@ RSpec.describe Form::Sales::Questions::ManagingOrganisation, type: :model do
let(:managing_org1) { create(:organisation, name: "Managing org 1") }
let(:managing_org2) { create(:organisation, name: "Managing org 2") }
let(:managing_org3) { create(:organisation, name: "Managing org 3") }
let(:inactive_org) { create(:organisation, name: "Inactive org", active: false) }
let(:log) do
create(:lettings_log, owning_organisation: log_owning_org, managing_organisation: managing_org1,
@ -80,7 +81,8 @@ RSpec.describe Form::Sales::Questions::ManagingOrganisation, type: :model do
}
end
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the managing agents of the current owning organisation" do
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the active managing agents of the current owning organisation" do
create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: inactive_org)
log_owning_org.update!(holds_own_stock: true)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
@ -96,7 +98,8 @@ RSpec.describe Form::Sales::Questions::ManagingOrganisation, type: :model do
}
end
it "shows current managing agent at top, followed by the managing agents of the current owning organisation" do
it "shows current managing agent at top, followed by the active managing agents of the current owning organisation" do
create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: inactive_org)
log_owning_org.update!(holds_own_stock: false)
expect(question.displayed_answer_options(log, user)).to eq(options)
end

20
spec/models/form/sales/questions/owning_organisation_id_spec.rb

@ -57,6 +57,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
let(:owning_org_1) { create(:organisation, name: "Owning org 1") }
let(:owning_org_2) { create(:organisation, name: "Owning org 2") }
let(:inactive_owning_org) { create(:organisation, name: "Inactive owning org", active: false) }
let(:non_stock_owner) { create(:organisation, name: "Non stock owner", holds_own_stock: false) }
let(:log) { create(:lettings_log, owning_organisation: owning_org_1) }
@ -75,7 +76,8 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
}
end
it "shows user organisation, current owning organisation and the stock owners that hold their stock" do
it "shows user organisation, current owning organisation and the activestock owners that hold their stock" do
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: inactive_owning_org)
user.organisation.update!(holds_own_stock: true)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
@ -95,7 +97,8 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: non_stock_owner)
end
it "shows current owning organisation and the stock owners that hold their stock" do
it "shows current owning organisation and the active stock owners that hold their stock" do
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: inactive_owning_org)
user.organisation.update!(holds_own_stock: false)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
@ -204,20 +207,21 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
context "when user is support" do
let(:user) { create(:user, :support, organisation: organisation_1) }
let(:log) { create(:lettings_log, created_by: user) }
let(:non_stock_organisation) { create(:organisation, holds_own_stock: false) }
let(:expected_opts) do
Organisation.where(holds_own_stock: true).each_with_object(options) do |organisation, hsh|
it "shows active orgs where organisation holds own stock" do
non_stock_organisation = create(:organisation, holds_own_stock: false)
inactive_org = create(:organisation, active: false)
expected_opts = Organisation.filter_by_active.where(holds_own_stock: true).each_with_object(options) do |organisation, hsh|
hsh[organisation.id] = organisation.name
hsh
end
end
it "shows orgs where organisation holds own stock" do
expect(question.displayed_answer_options(log, user)).to eq(expected_opts)
expect(question.displayed_answer_options(log, user)).not_to include(non_stock_organisation.id)
expect(question.displayed_answer_options(log, user)).not_to include(inactive_org.id)
expect(question.displayed_answer_options(log, user)).to include(organisation_1.id)
end
context "when an org has recently absorbed other orgs" do

5
spec/models/location_spec.rb

@ -870,6 +870,11 @@ RSpec.describe Location, type: :model do
expect(location.status).to eq(:deactivating_soon)
end
it "returns deactivated if the owning organisation is deactivated" do
location.scheme.owning_organisation.active = false
expect(location.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is in the past" do
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6), location:)
location.save!

41
spec/models/organisation_spec.rb

@ -212,8 +212,8 @@ RSpec.describe Organisation, type: :model do
describe "scopes" do
before do
create(:organisation, name: "Joe Bloggs")
create(:organisation, name: "Tom Smith")
create(:organisation, name: "Joe Bloggs", active: false)
create(:organisation, name: "Tom Smith", active: true)
end
context "when searching by name" do
@ -229,5 +229,42 @@ RSpec.describe Organisation, type: :model do
expect(described_class.search_by("joe").count).to eq(1)
end
end
context "when searching by active" do
it "returns case active records" do
results = described_class.filter_by_active
expect(results.count).to eq(1)
expect(results[0].name).to eq("Tom Smith")
end
end
end
describe "status" do
let!(:organisation) { create(:organisation) }
it "returns inactive when organisation inactive" do
organisation.active = false
expect(organisation.status).to be(:deactivated)
end
it "returns active when organisation active" do
organisation.active = true
expect(organisation.status).to be(:active)
end
it "returns merged when organisation merged in the past" do
organisation.merge_date = 1.month.ago
expect(organisation.status).to be(:merged)
end
it "does not return merged when organisation merges in the future" do
organisation.active = true
organisation.merge_date = Time.zone.now + 1.month
expect(organisation.status).to be(:active)
end
end
end

5
spec/models/scheme_spec.rb

@ -231,6 +231,11 @@ RSpec.describe Scheme, type: :model do
expect(scheme.status).to eq(:deactivating_soon)
end
it "returns deactivated if the owning organisation is deactivated" do
scheme.owning_organisation.active = false
expect(scheme.status).to eq(:deactivated)
end
it "returns deactivated if deactivation_date is in the past" do
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 6), scheme:)
scheme.reload

40
spec/policies/organisation_policy_spec.rb

@ -0,0 +1,40 @@
require "rails_helper"
# rubocop:disable RSpec/RepeatedExample
RSpec.describe OrganisationPolicy do
subject(:policy) { described_class }
let(:organisation) { FactoryBot.create(:organisation) }
let(:data_provider) { FactoryBot.create(:user, :data_provider) }
let(:data_coordinator) { FactoryBot.create(:user, :data_coordinator) }
let(:support) { FactoryBot.create(:user, :support) }
permissions :deactivate? do
it "does not permit data providers to deactivate an organisation" do
expect(policy).not_to permit(data_provider, organisation)
end
it "does not permit data coordinators to deactivate an organisation" do
expect(policy).not_to permit(data_coordinator, data_provider)
end
it "permits support users to deactivate an organisation" do
expect(policy).to permit(support, data_provider)
end
end
permissions :reactivate? do
it "does not permit data providers to reactivate an organisation" do
expect(policy).not_to permit(data_provider, organisation)
end
it "does not permit data coordinators to reactivate an organisation" do
expect(policy).not_to permit(data_coordinator, data_provider)
end
it "permits support users to reactivate an organisation" do
expect(policy).to permit(support, data_provider)
end
end
end
# rubocop:enable RSpec/RepeatedExample

28
spec/requests/organisation_relationships_controller_spec.rb

@ -18,11 +18,13 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
context "with an organisation that the user belongs to" do
let!(:stock_owner) { FactoryBot.create(:organisation) }
let!(:other_org_stock_owner) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:inactive_stock_owner) { FactoryBot.create(:organisation, name: "Inactive LTD", active: false) }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_stock_owner)
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: inactive_stock_owner)
get "/organisations/#{organisation.id}/stock-owners", headers:, params: {}
end
@ -46,11 +48,18 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(page).not_to have_content(other_org_stock_owner.name)
end
it "does not show inactive stock owners" do
expect(page).not_to have_content(inactive_stock_owner.name)
end
it "shows the pagination count" do
expect(page).to have_content("1 total stock owners")
end
context "when adding a stock owner" do
let!(:active_organisation) { FactoryBot.create(:organisation, name: "Active Org", active: true) }
let!(:inactive_organisation) { FactoryBot.create(:organisation, name: "Inactive LTD", active: false) }
before do
get "/organisations/#{organisation.id}/stock-owners/add", headers:, params: {}
end
@ -66,6 +75,11 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "shows a cancel button" do
expect(page).to have_link("Cancel", href: "/organisations/#{organisation.id}/stock-owners")
end
it "includes only active organisations as options" do
expect(response.body).to include(active_organisation.name)
expect(response.body).not_to include(inactive_organisation.name)
end
end
end
@ -84,11 +98,13 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
context "with an organisation that the user belongs to" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let!(:other_org_managing_agent) { FactoryBot.create(:organisation, name: "Foobar LTD") }
let!(:inactive_managing_agent) { FactoryBot.create(:organisation, name: "Inactive LTD", active: false) }
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") }
before do
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent)
FactoryBot.create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: other_org_managing_agent)
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: inactive_managing_agent)
get "/organisations/#{organisation.id}/managing-agents", headers:, params: {}
end
@ -112,12 +128,19 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(page).not_to have_content(other_org_managing_agent.name)
end
it "does not show inactive managing-agents" do
expect(page).not_to have_content(inactive_managing_agent.name)
end
it "shows the pagination count" do
expect(page).to have_content("1 total managing agents")
end
end
context "when adding a managing agent" do
let!(:active_organisation) { FactoryBot.create(:organisation, name: "Active Org", active: true) }
let!(:inactive_organisation) { FactoryBot.create(:organisation, name: "Inactive LTD", active: false) }
before do
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {}
end
@ -125,6 +148,11 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "has the correct header" do
expect(response.body).to include("What is the name of your managing agent?")
end
it "includes only active organisations as options" do
expect(response.body).to include(active_organisation.name)
expect(response.body).not_to include(inactive_organisation.name)
end
end
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do

112
spec/views/locations/show.html.erb_spec.rb

@ -1,50 +1,50 @@
require "rails_helper"
RSpec.describe "locations/show.html.erb" do
context "when a data provider" do
let(:user) { create(:user) }
let(:scheme) do
instance_double(
Scheme,
owning_organisation: user.organisation,
id: 1,
service_name: "some name",
id_to_display: "S1",
sensitive: false,
scheme_type: "some type",
registered_under_care_act: false,
arrangement_type: "some other type",
primary_client_group: false,
has_other_client_group: false,
secondary_client_group: false,
support_type: "some support type",
intended_stay: "some intended stay",
available_from: 1.week.ago,
scheme_deactivation_periods: [],
status: :active,
)
end
let(:scheme) do
instance_double(
Scheme,
owning_organisation: user.organisation,
id: 1,
service_name: "some name",
id_to_display: "S1",
sensitive: false,
scheme_type: "some type",
registered_under_care_act: false,
arrangement_type: "some other type",
primary_client_group: false,
has_other_client_group: false,
secondary_client_group: false,
support_type: "some support type",
intended_stay: "some intended stay",
available_from: 1.week.ago,
scheme_deactivation_periods: [],
status: :active,
)
end
let(:location) do
instance_double(
Location,
id: 5,
name: "some location",
postcode: "EC1N 2TD",
linked_local_authorities: [],
units: "",
type_of_unit: "",
mobility_type: "",
available_from: 1.week.ago,
location_deactivation_periods: [],
status: :active,
active?: true,
scheme:,
deactivates_in_a_long_time?: false,
is_la_inferred: nil,
)
end
let(:location) do
instance_double(
Location,
id: 5,
name: "some location",
postcode: "EC1N 2TD",
linked_local_authorities: [],
units: "",
type_of_unit: "",
mobility_type: "",
available_from: 1.week.ago,
location_deactivation_periods: [],
status: :active,
active?: true,
scheme:,
deactivates_in_a_long_time?: false,
is_la_inferred: nil,
)
end
context "when a data provider" do
let(:user) { create(:user) }
it "does not see add a location button" do
assign(:scheme, scheme)
@ -70,4 +70,32 @@ RSpec.describe "locations/show.html.erb" do
expect(rendered).not_to have_content("Change")
end
end
context "when a support user" do
let(:user) { create(:user, role: "support") }
it "sees deactivate scheme location button" do
assign(:scheme, scheme)
assign(:location, location)
allow(view).to receive(:current_user).and_return(user)
render
expect(rendered).to have_content("Deactivate this location")
end
it "does not see deactivate scheme location button when organisation is deactivated" do
user.organisation.active = false
assign(:scheme, scheme)
assign(:location, location)
allow(view).to receive(:current_user).and_return(user)
render
expect(rendered).not_to have_content("Deactivate this location")
end
end
end

14
spec/views/organisations/show.html.erb_spec.rb

@ -113,6 +113,20 @@ RSpec.describe "organisations/show.html.erb" do
expect(fragment).to have_link(text: "View agreement", href: "/organisations/#{organisation_with_dsa.id}/data-sharing-agreement")
end
end
it "shows deactivate button when organisation is active" do
user.organisation.active = true
render
expect(fragment).to have_content("Deactivate this organisation")
expect(fragment).not_to have_content("Reactivate this organisation")
end
it "shows reactivate button when organisation is inactive" do
user.organisation.active = false
render
expect(fragment).not_to have_content("Deactivate this organisation")
expect(fragment).to have_content("Reactivate this organisation")
end
end
context "when not dpo" do

34
spec/views/schemes/show.html.erb_spec.rb

@ -1,10 +1,15 @@
require "rails_helper"
RSpec.describe "schemes/show.html.erb" do
let(:organisation) { create(:organisation, holds_own_stock: true) }
let(:scheme) { create(:scheme, owning_organisation: organisation, confirmed: true) }
before do
create(:location, scheme:, confirmed: true)
end
context "when data provider" do
let(:organisation) { create(:organisation, holds_own_stock: true) }
let(:user) { build(:user, organisation:) }
let(:scheme) { create(:scheme, owning_organisation: user.organisation) }
it "does not render button to deactivate schemes" do
assign(:scheme, scheme)
@ -26,4 +31,29 @@ RSpec.describe "schemes/show.html.erb" do
expect(rendered).not_to have_content("Change")
end
end
context "when support" do
let(:user) { build(:user, organisation:, role: "support") }
it "renders button to deactivate scheme" do
assign(:scheme, scheme)
allow(view).to receive(:current_user).and_return(user)
render
expect(rendered).to have_content("Deactivate this scheme")
end
it "does not render button to deactivate scheme if organisation is deactivated" do
organisation.active = false
assign(:scheme, scheme)
allow(view).to receive(:current_user).and_return(user)
render
expect(rendered).not_to have_content("Deactivate this scheme")
end
end
end

Loading…
Cancel
Save