From 73c8e7f8afdac7a4867ccd712b197fa5473b8370 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 29 Jun 2023 13:00:12 +0100 Subject: [PATCH] Refactor policy and remove headers from tests --- app/policies/organisation_relationship_policy.rb | 2 +- .../organisation_relationships_controller_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/policies/organisation_relationship_policy.rb b/app/policies/organisation_relationship_policy.rb index 7b539eb5e..4b748f597 100644 --- a/app/policies/organisation_relationship_policy.rb +++ b/app/policies/organisation_relationship_policy.rb @@ -15,7 +15,7 @@ class OrganisationRelationshipPolicy remove_managing_agent? ].each do |method_name| define_method method_name do - return true unless user.data_provider? + !user.data_provider? end end end diff --git a/spec/requests/organisation_relationships_controller_spec.rb b/spec/requests/organisation_relationships_controller_spec.rb index 9e9f591a6..78b894b7f 100644 --- a/spec/requests/organisation_relationships_controller_spec.rb +++ b/spec/requests/organisation_relationships_controller_spec.rb @@ -297,7 +297,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do end context "when directly accessing the page to add a stock owner" do - let(:request) { get "/organisations/#{organisation.id}/stock-owners/add", headers: } + let(:request) { get "/organisations/#{organisation.id}/stock-owners/add" } it "returns 401" do request @@ -314,7 +314,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do }, } end - let(:request) { post "/organisations/#{organisation.id}/stock-owners", headers:, params: } + let(:request) { post "/organisations/#{organisation.id}/stock-owners", params: } it "returns 401" do request @@ -328,7 +328,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do context "when directly removing a stock owner" do let(:stock_owner) { FactoryBot.create(:organisation) } - let(:request) { get "/organisations/#{organisation.id}/stock-owners/remove?target_organisation_id=#{stock_owner.id}", headers: } + let(:request) { get "/organisations/#{organisation.id}/stock-owners/remove?target_organisation_id=#{stock_owner.id}" } before do FactoryBot.create(:organisation_relationship, parent_organisation: stock_owner, child_organisation: organisation) @@ -341,7 +341,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do end context "when directly accessing the page to add a managing agent" do - let(:request) { get "/organisations/#{organisation.id}/managing-agents/add", headers: } + let(:request) { get "/organisations/#{organisation.id}/managing-agents/add" } it "returns 401" do request @@ -358,7 +358,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do }, } end - let(:request) { post "/organisations/#{organisation.id}/managing-agents", headers:, params: } + let(:request) { post "/organisations/#{organisation.id}/managing-agents", params: } it "returns 401" do request @@ -372,7 +372,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do context "when directly removing a managing agent" do let(:managing_agent) { FactoryBot.create(:organisation) } - let(:request) { get "/organisations/#{organisation.id}/managing-agents/remove?target_organisation_id=#{managing_agent.id}", headers: } + let(:request) { get "/organisations/#{organisation.id}/managing-agents/remove?target_organisation_id=#{managing_agent.id}" } before do FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent)