Front now redirects to an appropriate page
This commit is contained in:
parent
42bcb46926
commit
2a70846a9d
3 changed files with 48 additions and 7 deletions
|
@ -1,17 +1,14 @@
|
||||||
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
||||||
class FrontController < ApplicationController
|
class FrontController < ApplicationController
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
flash.keep
|
if !Nonprofit.any?
|
||||||
if current_role?([:nonprofit_admin,:nonprofit_associate])
|
redirect_to onboard_path
|
||||||
|
elsif current_role?([:nonprofit_admin,:nonprofit_associate])
|
||||||
redirect_to NonprofitPath.dashboard(administered_nonprofit)
|
redirect_to NonprofitPath.dashboard(administered_nonprofit)
|
||||||
elsif current_user
|
elsif current_user
|
||||||
redirect_to '/profiles/' + current_user.profile.id.to_s
|
redirect_to '/profiles/' + current_user.profile.id.to_s
|
||||||
else
|
else
|
||||||
respond_to { |format| format.html }
|
redirect_to new_user_session_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
42
spec/controllers/front_spec.rb
Normal file
42
spec/controllers/front_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
||||||
|
require 'rails_helper'
|
||||||
|
require 'controllers/support/shared_user_context'
|
||||||
|
|
||||||
|
describe FrontController, :type => :controller do
|
||||||
|
describe 'authorization' do
|
||||||
|
include_context :shared_user_context
|
||||||
|
describe 'accept all' do
|
||||||
|
describe 'index' do
|
||||||
|
include_context :open_to_all, :get, :index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'index redirects to onboard with no non-profits' do
|
||||||
|
get( :index)
|
||||||
|
expect(response).to redirect_to onboard_url
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'have nonprofit info' do
|
||||||
|
include_context :shared_user_context
|
||||||
|
it 'redirect to nonprofit admin' do
|
||||||
|
sign_in user_as_np_admin
|
||||||
|
get(:index)
|
||||||
|
expect(response).to redirect_to NonprofitPath.dashboard(nonprofit)
|
||||||
|
end
|
||||||
|
it 'redirect to nonprofit admin' do
|
||||||
|
sign_in user_as_np_associate
|
||||||
|
get(:index)
|
||||||
|
expect(response).to redirect_to NonprofitPath.dashboard(nonprofit)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirect to general user' do
|
||||||
|
nonprofit
|
||||||
|
unauth_user.create_profile
|
||||||
|
sign_in unauth_user
|
||||||
|
get(:index)
|
||||||
|
expect(response).to redirect_to profile_url(unauth_user.profile.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -105,6 +105,8 @@ RSpec.shared_context :shared_user_context do
|
||||||
expect(response.status).to eq 302
|
expect(response.status).to eq 302
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias_method :redirects_to, :reject
|
||||||
|
|
||||||
def fix_args( *args)
|
def fix_args( *args)
|
||||||
replacements = {
|
replacements = {
|
||||||
__our_np: nonprofit.id,
|
__our_np: nonprofit.id,
|
||||||
|
|
Loading…
Reference in a new issue