From 6c171e3984c993b094b105117469fb37e1f096fb Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Thu, 18 May 2023 15:55:48 +0100 Subject: [PATCH] hide location toggle button for providers --- app/views/locations/show.html.erb | 5 +- spec/views/locations/show.html.erb_spec.rb | 57 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 spec/views/locations/show.html.erb_spec.rb diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index 005d68422..ca2429fed 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -22,6 +22,9 @@ <% end %> -<% if FeatureToggle.location_toggle_enabled? && user_can_edit_scheme?(current_user, @scheme) %> + +<% if FeatureToggle.location_toggle_enabled? %> + <% if LocationPolicy.new(current_user, Location).deactivate? %> <%= toggle_location_link(@location) %> + <% end %> <% end %> diff --git a/spec/views/locations/show.html.erb_spec.rb b/spec/views/locations/show.html.erb_spec.rb new file mode 100644 index 000000000..0a17c248a --- /dev/null +++ b/spec/views/locations/show.html.erb_spec.rb @@ -0,0 +1,57 @@ +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(:location) do + instance_double( + Location, + 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:, + ) + end + + it "does not see add a location button" do + 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