BigW Consortium Gitlab

repositories_controller_spec.rb 1.24 KB
Newer Older
Douwe Maan committed
1 2 3
require "spec_helper"

describe Projects::RepositoriesController do
4
  let(:project) { create(:project, :repository) }
Douwe Maan committed
5 6

  describe "GET archive" do
7 8
    context 'as a guest' do
      it 'responds with redirect in correct format' do
9
        get :archive, namespace_id: project.namespace, project_id: project, format: "zip"
Douwe Maan committed
10

11
        expect(response.header["Content-Type"]).to start_with('text/html')
12 13
        expect(response).to be_redirect
      end
Douwe Maan committed
14 15
    end

16 17
    context 'as a user' do
      let(:user) { create(:user) }
Douwe Maan committed
18 19

      before do
20 21
        project.team << [user, :developer]
        sign_in(user)
Douwe Maan committed
22 23
      end

24
      it "uses Gitlab::Workhorse" do
25
        get :archive, namespace_id: project.namespace, project_id: project, ref: "master", format: "zip"
26 27

        expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
28 29 30 31 32 33 34 35
      end

      context "when the service raises an error" do
        before do
          allow(Gitlab::Workhorse).to receive(:send_git_archive).and_raise("Archive failed")
        end

        it "renders Not Found" do
36
          get :archive, namespace_id: project.namespace, project_id: project, ref: "master", format: "zip"
Douwe Maan committed
37

38
          expect(response).to have_http_status(404)
39
        end
Douwe Maan committed
40 41 42 43
      end
    end
  end
end