docbrown/spec/requests/shared_examples/internal_policy_dependant_request.rb
Mac Siri d976eb7ab6 Create InternalPolicy (#4380)
* Ensure verify_authorized in internal

* Create internal_policy

* Replace ArticlePolicy usage with InternalPolicy

* Replace BufferUpdate&CommentPolicy with InternalPolicy

* Remove verbose authorize_admin

* Forgot to remove coresponding specs

* Create specs for InternalPolicy

* Expand policy access on internal's broadcast

* Refactor

* Create shared spec

* Create request specs

* Add additional test cases
2019-10-17 14:21:43 -04:00

30 lines
872 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: true 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