summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/commits_controller_spec.rb
blob: c459d7325073abbee6b60ad2c634774ff8648433 (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
66
67
68
69
70
71
72
73
74
75
require 'spec_helper'

describe Projects::CommitsController do
  let(:project) { create(:project, :repository) }
  let(:user) { create(:user) }

  before do
    sign_in(user)
    project.team << [user, :master]
  end

  describe "GET show" do
    render_views

    context 'with file path' do
      before do
        get(:show,
            namespace_id: project.namespace,
            project_id: project,
            id: id)
      end

      context "valid branch, valid file" do
        let(:id) { 'master/README.md' }

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

      context "valid branch, invalid file" do
        let(:id) { 'master/invalid-path.rb' }

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

      context "invalid branch, valid file" do
        let(:id) { 'invalid-branch/README.md' }

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

    context "when the ref name ends in .atom" do
      context "when the ref does not exist with the suffix" do
        it "renders as atom" do
          get(:show,
              namespace_id: project.namespace,
              project_id: project,
              id: "master.atom")

          expect(response).to be_success
          expect(response.content_type).to eq('application/atom+xml')
        end
      end

      context "when the ref exists with the suffix" do
        before do
          commit = project.repository.commit('master')

          allow_any_instance_of(Repository).to receive(:commit).and_call_original
          allow_any_instance_of(Repository).to receive(:commit).with('master.atom').and_return(commit)

          get(:show,
              namespace_id: project.namespace,
              project_id: project,
              id: "master.atom")
        end

        it "renders as HTML" do
          expect(response).to be_success
          expect(response.content_type).to eq('text/html')
        end
      end
    end
  end
end