From 8ad366f46312a8439fe30a599e60f489b52ff028 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 17 May 2023 16:39:01 +0100 Subject: [PATCH] hide create scheme button for providers --- app/views/organisations/schemes.html.erb | 4 +++- app/views/schemes/index.html.erb | 4 +++- .../organisations/schemes.html.erb_spec.rb | 19 +++++++++++++++++++ spec/views/schemes/index.html.erb_spec.rb | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 spec/views/organisations/schemes.html.erb_spec.rb create mode 100644 spec/views/schemes/index.html.erb_spec.rb diff --git a/app/views/organisations/schemes.html.erb b/app/views/organisations/schemes.html.erb index 8e9690fe5..6dac0f3a7 100644 --- a/app/views/organisations/schemes.html.erb +++ b/app/views/organisations/schemes.html.erb @@ -12,7 +12,9 @@

Supported housing schemes

<% end %> -<%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %> +<% if SchemePolicy.new(current_user, nil).create? %> + <%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %> +<% end %> <%= govuk_details( classes: "govuk-!-width-two-thirds", diff --git a/app/views/schemes/index.html.erb b/app/views/schemes/index.html.erb index 8e787a33d..fa900ca8d 100644 --- a/app/views/schemes/index.html.erb +++ b/app/views/schemes/index.html.erb @@ -5,7 +5,9 @@ <%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Supported housing schemes", sub: nil } : { main: "Supported housing schemes", sub: current_user.organisation.name } %> -<%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %> +<% if SchemePolicy.new(current_user, nil).create? %> + <%= govuk_button_link_to "Create a new supported housing scheme", new_scheme_path, html: { method: :post } %> +<% end %> <%= render SearchComponent.new(current_user:, search_label: "Search by scheme name, code, postcode or location name", value: @searched) %> diff --git a/spec/views/organisations/schemes.html.erb_spec.rb b/spec/views/organisations/schemes.html.erb_spec.rb new file mode 100644 index 000000000..5c4bff422 --- /dev/null +++ b/spec/views/organisations/schemes.html.erb_spec.rb @@ -0,0 +1,19 @@ +require "rails_helper" + +RSpec.describe "organisations/schemes.html.erb" do + context "when data provider" do + let(:user) { build(:user) } + + it "does not render button to create schemes" do + assign(:organisation, user.organisation) + assign(:pagy, Pagy.new(count: 0, page: 1)) + assign(:schemes, []) + + allow(view).to receive(:current_user).and_return(user) + + render + + expect(rendered).not_to have_content("Create a new supported housing scheme") + end + end +end diff --git a/spec/views/schemes/index.html.erb_spec.rb b/spec/views/schemes/index.html.erb_spec.rb new file mode 100644 index 000000000..86a8610c0 --- /dev/null +++ b/spec/views/schemes/index.html.erb_spec.rb @@ -0,0 +1,18 @@ +require "rails_helper" + +RSpec.describe "schemes/index.html.erb" do + context "when data provider" do + let(:user) { build(:user) } + + it "does not render button to create schemes" do + assign(:pagy, Pagy.new(count: 0, page: 1)) + assign(:schemes, []) + + allow(view).to receive(:current_user).and_return(user) + + render + + expect(rendered).not_to have_content("Create a new supported housing scheme") + end + end +end