docbrown/spec/requests/shared_examples/internal_policy_dependant_request.rb
Anna Buianova 20e242af0d
Rubocop fixes (#20254)
* Fixed redundant alls for rubocop

* Fixed rubocop violations in spec/requests

* Fixed rubocop violations in spec/models

* Fixed Performance/MapMethodChain

* Fixed rubocop violations in spec/requests

* Revert changes to FastlyConfig::Update spec
2023-10-18 17:24:28 -04:00

30 lines
867 B
Ruby

RSpec.shared_examples "an InternalPolicy dependant request" do |resource|
let(:user) { create(:user) }
context "when user is a single_resource_admin" do
before do
user.add_role(:single_resource_admin, resource)
sign_in user
allow(InternalPolicy).to receive(:new).and_call_original
end
it "responds with 200 OK" do
request
expect(response).to have_http_status(:success)
expect(InternalPolicy).to have_received(:new).with(user, resource)
end
end
context "when user is not an admin", :proper_status do
before do
sign_in user
allow(InternalPolicy).to receive(:new).and_call_original
end
it "responds with 404 not_found" do
request
expect(response).to have_http_status(:not_found)
expect(InternalPolicy).to have_received(:new).with(user, resource)
end
end
end