Read about our upcoming Code of Conduct on this issue

projects_controller_spec.rb 1.8 KB
Newer Older
1
2
# frozen_string_literal: true

3
4
5
require 'spec_helper'

describe Dashboard::ProjectsController do
6
7
8
9
10
11
12
13
  include ExternalAuthorizationServiceHelpers

  describe '#index' do
    context 'user not logged in' do
      it_behaves_like 'authenticates sessionless user', :index, :atom
    end

    context 'user logged in' do
14
15
      let(:user) { create(:user) }

16
      before do
17
        sign_in(user)
18
19
20
21
22
23
24
25
26
27
28
      end

      context 'external authorization' do
        it 'works when the external authorization service is enabled' do
          enable_external_authorization_service_check

          get :index

          expect(response).to have_gitlab_http_status(200)
        end
      end
29
30
31
32
33
34
35
36
37
38
39
40
41
42

      it 'orders the projects by last activity by default' do
        project = create(:project)
        project.add_developer(user)
        project.update!(last_repository_updated_at: 3.days.ago, last_activity_at: 3.days.ago)

        project2 = create(:project)
        project2.add_developer(user)
        project2.update!(last_repository_updated_at: 10.days.ago, last_activity_at: 10.days.ago)

        get :index

        expect(assigns(:projects)).to eq([project, project2])
      end
George Koltsov's avatar
George Koltsov committed
43
44
45
46
47
48
49
50

      context 'project sorting' do
        let(:project) { create(:project) }

        it_behaves_like 'set sort order from user preference' do
          let(:sorting_param) { 'created_asc' }
        end
      end
51
52
    end
  end
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

  context 'json requests' do
    render_views

    let(:user) { create(:user) }

    before do
      sign_in(user)
    end

    describe 'GET /projects.json' do
      before do
        get :index, format: :json
      end

      it { is_expected.to respond_with(:success) }
    end

    describe 'GET /starred.json' do
      before do
        get :starred, format: :json
      end

      it { is_expected.to respond_with(:success) }
    end
  end
79
end