diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb new file mode 100644 index 000000000..3bf635f8b --- /dev/null +++ b/app/controllers/root_controller.rb @@ -0,0 +1,14 @@ +class RootController < ApplicationController + def index + + if user_signed_in? + redirect_to users_dossiers_path + elsif gestionnaire_signed_in? + redirect_to backoffice_path + elsif administrateur_signed_in? + redirect_to admin_procedures_path + else + redirect_to new_user_session_path + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1c64b1d95..10a95be41 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,8 @@ Rails.application.routes.draw do sessions: 'users/sessions' } - root 'users/dossiers#index' + #root 'users/dossiers#index' + root 'root#index' get 'france_connect' => 'france_connect#login' get 'france_connect/callback' => 'france_connect#callback' diff --git a/spec/controllers/root_controller_spec.rb b/spec/controllers/root_controller_spec.rb new file mode 100644 index 000000000..607767093 --- /dev/null +++ b/spec/controllers/root_controller_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe RootController, type: :controller do + + subject { get :index } + + context 'when User is connected' do + before do + sign_in create(:user) + end + + it { expect(subject).to redirect_to(users_dossiers_path) } + end + + context 'when Gestionnaire is connected' do + before do + sign_in create(:gestionnaire) + end + + it { expect(subject).to redirect_to(backoffice_path) } + end + + context 'when Administrateur is connected' do + before do + sign_in create(:administrateur) + end + + it { expect(subject).to redirect_to(admin_procedures_path) } + end + + context 'when nobody is connected' do + it { expect(subject).to redirect_to(new_user_session_path) } + end +end \ No newline at end of file