demarches-normaliennes/spec/controllers/api_controller_spec.rb

31 lines
782 B
Ruby
Raw Normal View History

2015-12-21 17:51:49 +01:00
require 'spec_helper'
describe APIController, type: :controller do
controller(APIController) do
def show
render json: {}, satus: 200
end
2015-12-21 17:51:49 +01:00
def index
render json: {}, satus: 200
end
end
describe 'GET index' do
context 'when token is missing' do
subject { get :index }
it { expect(subject.status).to eq(401) }
2015-12-21 17:51:49 +01:00
end
context 'when token does not exist' do
let(:token) { 'invalid_token' }
subject { get :index, params: {token: token} }
it { expect(subject.status).to eq(401) }
2015-12-21 17:51:49 +01:00
end
context 'when token exist' do
let(:administrateur) { create(:administrateur) }
subject { get :index, params: {token: administrateur.api_token} }
it { expect(subject.status).to eq(200) }
2015-12-21 17:51:49 +01:00
end
end
2017-04-04 15:27:04 +02:00
end