demarches-normaliennes/spec/controllers/administrations/omniauth_callbacks_controller_spec.rb

37 lines
1,023 B
Ruby
Raw Normal View History

2017-12-20 15:27:33 +01:00
describe Administrations::OmniauthCallbacksController, type: :controller do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:administration]
end
describe 'POST #github' do
let(:params) { { "info" => { "email" => email } } }
before do
2018-01-09 14:37:39 +01:00
allow(controller).to receive(:sign_in).and_return true
2017-12-20 15:27:33 +01:00
@request.env["omniauth.auth"] = params
end
subject { post :github }
context 'with an authorized email' do
let(:email) { "ivan@tps.fr" }
let(:administration) { create(:administration, email: email) }
before { administration }
2018-01-16 17:09:25 +01:00
it { is_expected.to redirect_to(manager_administrateurs_path) }
2017-12-20 15:27:33 +01:00
it do
expect(controller).to receive(:sign_in).with(administration)
subject
end
end
context 'with an unauthorized email' do
let(:email) { "michel@tps.fr" }
it { is_expected.to redirect_to(root_path) }
it do
expect(controller).to_not receive(:sign_in)
subject
end
end
end
end