summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/releases_controller_spec.rb
blob: f170a2ab61321f3ac5f00b8e046e2b8dfca97593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

require 'spec_helper'

describe Projects::ReleasesController do
  let!(:project) { create(:project, :repository, :public) }
  let!(:user)    { create(:user) }

  before do
    stub_feature_flags(releases_page: true)
  end

  describe 'GET #index' do
    it 'renders a 200' do
      get_index

      expect(response.status).to eq(200)
    end

    context 'when the project is private' do
      let!(:project) { create(:project, :repository, :private) }

      it 'renders a 302' do
        get_index

        expect(response.status).to eq(302)
      end

      it 'renders a 200 for a logged in developer' do
        project.add_developer(user)
        sign_in(user)

        get_index

        expect(response.status).to eq(200)
      end

      it 'renders a 404 when logged in but not in the project' do
        sign_in(user)

        get_index

        expect(response.status).to eq(404)
      end
    end

    context 'when releases_page feature flag is disabled' do
      before do
        stub_feature_flags(releases_page: false)
      end

      it 'renders a 404' do
        get_index

        expect(response.status).to eq(404)
      end
    end
  end

  private

  def get_index
    get :index, params: { namespace_id: project.namespace, project_id: project }
  end
end