Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rspec'
- module Authenticable
- def current_user
- @current_user ||= 'Pedro'
- end
- def authenticate_with_token!
- render json: { errors: "Not authenticated" },
- status: :unauthorized unless user_signed_in?
- end
- def user_signed_in?
- current_user != nil
- end
- end
- class Authentication
- include Authenticable
- end
- RSpec.describe Authenticable do
- let(:authentication) { Authentication.new }
- subject { authentication }
- describe '.authenticate_with_token' do
- before do
- allow(authentication).to receive(:current_user).and_return(nil)
- allow(authentication).to receive(:render) do |args|
- args
- end
- end
- it 'returns error' do
- expect(authentication.authenticate_with_token![:json][:errors]).to eq 'Not authenticated'
- end
- it 'returns unauthorized status' do
- expect(authentication.authenticate_with_token![:status]).to eq :unauthorized
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement