BigW Consortium Gitlab

projects_controller_spec.rb 1.65 KB
Newer Older
1 2 3 4 5 6 7
require 'spec_helper'

describe Ci::ProjectsController do
  let(:visibility) { :public }
  let!(:project) { create(:project, visibility, ci_id: 1) }
  let(:ci_id) { project.ci_id }

8
  describe '#index' do
9 10 11 12 13
    context 'user signed in' do
      before do
        sign_in(create(:user))
        get(:index)
      end
14

15 16 17 18 19 20 21 22 23 24 25
      it 'redirects to /' do
        expect(response).to redirect_to(root_path)
      end
    end

    context 'user not signed in' do
      before { get(:index) }

      it 'redirects to sign in page' do
        expect(response).to redirect_to(new_user_session_path)
      end
26 27 28
    end
  end

29 30 31 32
  ##
  # Specs for *deprecated* CI badge
  #
  describe '#badge' do
33 34 35 36 37 38 39 40
    shared_examples 'badge provider' do
      it 'shows badge' do
        expect(response.status).to eq 200
        expect(response.headers)
          .to include('Content-Type' => 'image/svg+xml')
      end
    end

41
    context 'user not signed in' do
42 43 44 45 46 47 48 49 50 51 52 53
      before { get(:badge, id: ci_id) }

      context 'project has no ci_id reference' do
        let(:ci_id) { 123 }

        it 'returns 404' do
          expect(response.status).to eq 404
        end
      end

      context 'project is public' do
        let(:visibility) { :public }
54
        it_behaves_like 'badge provider'
55 56 57 58
      end

      context 'project is private' do
        let(:visibility) { :private }
59
        it_behaves_like 'badge provider'
60
      end
61
    end
62 63 64 65 66 67 68 69

    context 'user signed in' do
      let(:user) { create(:user) }
      before { sign_in(user) }
      before { get(:badge, id: ci_id) }

      context 'private is internal' do
        let(:visibility) { :internal }
70
        it_behaves_like 'badge provider'
71 72 73 74
      end
    end
  end
end