Welcome to mirror list, hosted at ThFree Co, Russian Federation.

last_commit_resolver_spec.rb « resolvers « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 82bbdd4487c5802e0c1dc89faadc171d7e7588f1 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Resolvers::LastCommitResolver do
  include GraphqlHelpers
  include RepoHelpers

  let(:project) { create(:project, :repository) }
  let(:repository) { project.repository }
  let(:tree) { repository.tree(ref, path) }

  let(:commit) { resolve(described_class, obj: tree) }

  describe '#resolve' do
    context 'last commit is a merge commit' do
      let(:ref) { 'master' }
      let(:path) { '/' }

      it 'resolves to the merge commit' do
        expect(commit).to eq(repository.commits(ref, limit: 1).last)
      end
    end

    context 'last commit for a different branch and path' do
      let(:ref) { 'fix' }
      let(:path) { 'files' }

      it 'resolves commit' do
        expect(commit).to eq(repository.commits(ref, path: path, limit: 1).last)
      end
    end

    context 'last commit for a wildcard pathspec' do
      let(:ref) { 'fix' }
      let(:path) { 'files/*' }

      it 'returns nil' do
        expect(commit).to be_nil
      end
    end

    context 'last commit with pathspec characters' do
      let(:ref) { 'fix' }
      let(:path) { ':wq' }

      before do
        create_file_in_repo(project, ref, ref, path, 'Test file')
      end

      it 'resolves commit' do
        expect(commit).to eq(repository.commits(ref, path: path, limit: 1).last)
      end
    end

    context 'last commit does not exist' do
      let(:ref) { 'master' }
      let(:path) { 'does-not-exist' }

      it 'returns nil' do
        expect(commit).to be_nil
      end
    end

    context 'when the ref is ambiguous' do
      let(:ambiguous_ref) { 'v1.0.0' }

      before do
        project.repository.create_branch(ambiguous_ref)
      end

      context 'when tree is for a tag' do
        let(:tree) { repository.tree(ambiguous_ref, ref_type: 'tags') }

        it 'resolves commit' do
          expect(commit.id).to eq(repository.find_tag(ambiguous_ref).dereferenced_target.id)
        end
      end

      context 'when tree is for a branch' do
        let(:tree) { repository.tree(ambiguous_ref, ref_type: 'heads') }

        it 'resolves commit' do
          expect(commit.id).to eq(repository.find_branch(ambiguous_ref).target)
        end
      end
    end
  end
end