BigW Consortium Gitlab

root_controller_spec.rb 2.54 KB
Newer Older
Robert Speicher committed
1 2 3
require 'spec_helper'

describe RootController do
4
  describe 'GET index' do
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
    context 'when user is not logged in' do
      it 'redirects to the sign-in page' do
        get :index

        expect(response).to redirect_to(new_user_session_path)
      end

      context 'when a custom home page URL is defined' do
        before do
          stub_application_setting(home_page_url: 'https://gitlab.com')
        end

        it 'redirects the user to the custom home page URL' do
          get :index

          expect(response).to redirect_to('https://gitlab.com')
        end
      end
    end

Robert Speicher committed
25 26 27 28 29 30 31 32
    context 'with a user' do
      let(:user) { create(:user) }

      before do
        sign_in(user)
        allow(subject).to receive(:current_user).and_return(user)
      end

33
      context 'who has customized their dashboard setting for starred projects' do
Robert Speicher committed
34
        before do
35
          user.dashboard = 'stars'
Robert Speicher committed
36 37 38
        end

        it 'redirects to their specified dashboard' do
39
          get :index
40

Robert Speicher committed
41 42 43 44
          expect(response).to redirect_to starred_dashboard_projects_path
        end
      end

45 46
      context 'who has customized their dashboard setting for project activities' do
        before do
47
          user.dashboard = 'project_activity'
48 49 50 51
        end

        it 'redirects to the activity list' do
          get :index
52

53 54 55 56 57 58
          expect(response).to redirect_to activity_dashboard_path
        end
      end

      context 'who has customized their dashboard setting for starred project activities' do
        before do
59
          user.dashboard = 'starred_project_activity'
60 61 62 63
        end

        it 'redirects to the activity list' do
          get :index
64

65 66 67 68
          expect(response).to redirect_to activity_dashboard_path(filter: 'starred')
        end
      end

69 70
      context 'who has customized their dashboard setting for groups' do
        before do
71
          user.dashboard = 'groups'
72 73 74 75
        end

        it 'redirects to their group list' do
          get :index
76

77 78 79 80 81 82
          expect(response).to redirect_to dashboard_groups_path
        end
      end

      context 'who has customized their dashboard setting for todos' do
        before do
83
          user.dashboard = 'todos'
84 85 86 87
        end

        it 'redirects to their todo list' do
          get :index
88

89 90 91 92
          expect(response).to redirect_to dashboard_todos_path
        end
      end

Robert Speicher committed
93 94
      context 'who uses the default dashboard setting' do
        it 'renders the default dashboard' do
95
          get :index
96

97
          expect(response).to render_template 'dashboard/projects/index'
Robert Speicher committed
98 99 100 101 102
        end
      end
    end
  end
end