mastodon/spec/support/examples/api.rb
David Roetzel d2f82d402a
Add shared context for API authentication
And use it in request specs.
2025-11-21 16:18:28 +01:00

25 lines
682 B
Ruby

# frozen_string_literal: true
RSpec.shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
# Some examples have a subject which needs to be called to make a request
subject if request.nil?
expect(response).to have_http_status(403)
end
end
RSpec.shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
let(:user) { Fabricate(:user, role:) }
it 'returns http forbidden' do
# Some examples have a subject which needs to be called to make a request
subject if request.nil?
expect(response).to have_http_status(403)
end
end