Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

andriy-baran

🎯
Focusing
View GitHub Profile
View protected_endpoint.rb
RSpec.shared_examples 'protected endpoint' do |http_method|
context 'when api user unless they haven\'t provided access token' do
it 'renders not logged in message' do
public_send(http_method, path, valid_params) # No valid headers
expect(response.body).to eq 'Not logged in'
end
end
end
View api_session.rb
RSpec.shared_context 'api session', shared_context: :metadata do
let(:domain) { 'good.co' }
let(:email) { "#{SecureRandom.hex}@#{domain}" }
let(:user) { FactoryBot.create(:user, email: email) }
let(:valid_headers) { {} }
let(:valid_headers) do
{
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-API-Token' => user.api_key