demarches-normaliennes/spec/controllers/api_controller_spec.rb

39 lines
1,003 B
Ruby
Raw Normal View History

2015-12-21 17:51:49 +01:00
require 'spec_helper'
describe APIController, type: :controller do
describe 'valid_token_for_administrateur?' do
let!(:admin) { create(:administrateur) }
subject { controller.send(:'valid_token_for_administrateur?', admin) }
context 'when the admin has not any token' do
context 'and the token is not given' do
it { is_expected.to be false }
end
2015-12-21 17:51:49 +01:00
end
context 'when the admin has a token' do
let!(:token) { admin.renew_api_token }
context 'and the token is given by params' do
before { controller.params[:token] = token }
it { is_expected.to be true }
end
context 'and the token is given by header' do
before do
valid_headers = { 'Authorization' => "Bearer token=#{token}" }
request.headers.merge!(valid_headers)
end
it { is_expected.to be true }
end
context 'and the token is not given' do
it { is_expected.to be false }
end
2015-12-21 17:51:49 +01:00
end
end
2017-04-04 15:27:04 +02:00
end