Redirect users after sign in to their desired page

This commit is contained in:
Sebastian Serth
2023-11-30 23:01:39 +01:00
parent cee3ceb188
commit 5ddc5a8ca5
7 changed files with 84 additions and 18 deletions

View File

@ -30,11 +30,26 @@ RSpec.describe ApplicationController do
describe '#render_not_authorized' do
before do
allow(controller).to receive(:welcome) { controller.send(:render_not_authorized) }
login_user(user) if defined?(user)
get :welcome
end
expect_flash_message(:alert, I18n.t('application.not_authorized'))
expect_redirect(:root)
expect_flash_message(:alert, I18n.t('application.not_signed_in'))
expect_redirect(:sign_in)
context 'with an admin' do
let(:user) { create(:admin) }
expect_flash_message(:alert, I18n.t('application.not_authorized'))
expect_redirect(:root)
end
context 'with a teacher' do
let(:user) { create(:teacher) }
expect_flash_message(:alert, I18n.t('application.not_authorized'))
expect_redirect(:root)
end
end
describe '#render_not_found' do
@ -44,19 +59,21 @@ RSpec.describe ApplicationController do
get :welcome
end
expect_flash_message(:alert, I18n.t('application.not_authorized'))
expect_redirect(:root)
expect_flash_message(:alert, I18n.t('application.not_signed_in'))
expect_redirect(:sign_in)
context 'with an admin' do
let(:user) { create(:admin) }
expect_flash_message(:alert, I18n.t('application.not_found'))
expect_redirect(:root)
end
context 'with a teacher' do
let(:user) { create(:teacher) }
expect_flash_message(:alert, I18n.t('application.not_authorized'))
expect_redirect(:root)
end
end