commits_controller_spec.rb 2.1 KB
Newer Older
1 2
require 'spec_helper'

3
describe Projects::CommitsController do
4
  let(:project) { create(:project, :repository) }
I
Izaak Alpert 已提交
5
  let(:user) { create(:user) }
6 7 8

  before do
    sign_in(user)
9
    project.add_master(user)
10 11 12
  end

  describe "GET show" do
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    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' }
31

32 33 34 35 36 37 38 39 40 41 42
        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
43
      context "when the ref does not exist with the suffix" do
J
Jacopo 已提交
44
        before do
45
          get(:show,
46 47
              namespace_id: project.namespace,
              project_id: project,
48
              id: "master.atom")
J
Jacopo 已提交
49
        end
50

J
Jacopo 已提交
51
        it "renders as atom" do
52 53 54
          expect(response).to be_success
          expect(response.content_type).to eq('application/atom+xml')
        end
J
Jacopo 已提交
55 56 57 58

        it 'renders summary with type=html' do
          expect(response.body).to include('<summary type="html">')
        end
59 60 61 62 63 64 65 66 67 68
      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,
69 70
              namespace_id: project.namespace,
              project_id: project,
71 72 73 74 75 76 77
              id: "master.atom")
        end

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