Stub instructeur devise methods in spec

This commit is contained in:
simon lehericey 2019-08-08 17:36:08 +02:00
parent c8a7bde5e0
commit 0d71a820a8
4 changed files with 26 additions and 18 deletions

View file

@ -4,6 +4,7 @@ describe 'instructeurs/dossiers/show.html.haml', type: :view do
before do
sign_in current_instructeur
allow(view).to receive(:current_instructeur).and_return(current_instructeur)
assign(:dossier, dossier)
end

View file

@ -6,36 +6,34 @@ describe 'layouts/_navbar.html.haml', type: :view do
let!(:procedure) { create(:procedure, administrateur: administrateur) }
before do
allow(view).to receive(:instructeur_signed_in?).and_return(instructeur_signed_in)
allow(view).to receive(:administrateur_signed_in?).and_return(administrateur_signed_in)
end
describe 'navbar entries' do
before { render }
subject { rendered }
context 'when disconnected' do
before do
render
end
subject { rendered }
let(:instructeur_signed_in) { false }
let(:administrateur_signed_in) { false }
it { is_expected.to match(/Connexion/) }
end
context 'when administrateur is connected' do
before do
@request.env["devise.mapping"] = Devise.mappings[:administrateur]
@current_user = administrateur
sign_in @current_user
render
end
let(:instructeur_signed_in) { false }
let(:administrateur_signed_in) { true }
subject { rendered }
it { is_expected.to match(/Déconnexion/) }
end
context 'when instructeur is connected' do
before do
@request.env["devise.mapping"] = Devise.mappings[:instructeur]
@current_user = instructeur
sign_in @current_user
render
end
let(:instructeur_signed_in) { true }
let(:administrateur_signed_in) { false }
subject { rendered }
it { is_expected.to match(/Déconnexion/) }
end
end

View file

@ -1,8 +1,13 @@
require 'spec_helper'
describe 'layouts/_new_header.html.haml', type: :view do
let(:current_instructeur) { nil }
before do
allow(view).to receive(:multiple_devise_profile_connect?).and_return(false)
allow(view).to receive(:instructeur_signed_in?).and_return((profile == :instructeur))
allow(view).to receive(:current_instructeur).and_return(current_instructeur)
if user
sign_in user
allow(controller).to receive(:nav_bar_profile).and_return(profile)

View file

@ -4,6 +4,10 @@ describe 'layouts/procedure_context.html.haml', type: :view do
let(:procedure) { create(:simple_procedure, :with_service) }
let(:dossier) { create(:dossier, procedure: procedure) }
before do
allow(view).to receive(:instructeur_signed_in?).and_return(false)
end
subject do
render html: 'Column content', layout: 'layouts/procedure_context.html.haml'
end