Browse Source

Refactor policy and remove headers from tests

pull/1729/head
Kat 3 years ago
parent
commit
73c8e7f8af
  1. 2
      app/policies/organisation_relationship_policy.rb
  2. 12
      spec/requests/organisation_relationships_controller_spec.rb

2
app/policies/organisation_relationship_policy.rb

@ -15,7 +15,7 @@ class OrganisationRelationshipPolicy
remove_managing_agent? remove_managing_agent?
].each do |method_name| ].each do |method_name|
define_method method_name do define_method method_name do
return true unless user.data_provider? !user.data_provider?
end end
end end
end end

12
spec/requests/organisation_relationships_controller_spec.rb

@ -297,7 +297,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
context "when directly accessing the page to add a stock owner" do 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 it "returns 401" do
request request
@ -314,7 +314,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
}, },
} }
end end
let(:request) { post "/organisations/#{organisation.id}/stock-owners", headers:, params: } let(:request) { post "/organisations/#{organisation.id}/stock-owners", params: }
it "returns 401" do it "returns 401" do
request request
@ -328,7 +328,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
context "when directly removing a stock owner" do context "when directly removing a stock owner" do
let(:stock_owner) { FactoryBot.create(:organisation) } 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 before do
FactoryBot.create(:organisation_relationship, parent_organisation: stock_owner, child_organisation: organisation) FactoryBot.create(:organisation_relationship, parent_organisation: stock_owner, child_organisation: organisation)
@ -341,7 +341,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end end
context "when directly accessing the page to add a managing agent" do 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 it "returns 401" do
request request
@ -358,7 +358,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
}, },
} }
end end
let(:request) { post "/organisations/#{organisation.id}/managing-agents", headers:, params: } let(:request) { post "/organisations/#{organisation.id}/managing-agents", params: }
it "returns 401" do it "returns 401" do
request request
@ -372,7 +372,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
context "when directly removing a managing agent" do context "when directly removing a managing agent" do
let(:managing_agent) { FactoryBot.create(:organisation) } 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 before do
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent) FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent)

Loading…
Cancel
Save