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

position_tracer_helpers.rb « helpers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bbf6e06dd4042d1003006c85006efb5d443fa68c (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
90
91
92
93
# frozen_string_literal: true

module PositionTracerHelpers
  def diff_refs(base_commit, head_commit)
    Gitlab::Diff::DiffRefs.new(base_sha: base_commit.id, head_sha: head_commit.id)
  end

  def position(attrs = {})
    attrs.reverse_merge!(
      diff_refs: old_diff_refs
    )
    Gitlab::Diff::Position.new(attrs)
  end

  def expect_new_position(attrs, result = subject)
    aggregate_failures("expect new position #{attrs.inspect}") do
      if attrs.nil?
        expect(result[:outdated]).to be_truthy
      else
        new_position = result[:position]

        expect(result[:outdated]).to be_falsey
        expect(new_position).not_to be_nil
        expect(new_position.diff_refs).to eq(new_diff_refs)

        attrs.each do |attr, value|
          expect(new_position.send(attr)).to eq(value)
        end
      end
    end
  end

  def expect_change_position(attrs, result = subject)
    aggregate_failures("expect change position #{attrs.inspect}") do
      change_position = result[:position]

      expect(result[:outdated]).to be_truthy

      if attrs.nil? || attrs.empty?
        expect(change_position).to be_nil
      else
        expect(change_position).not_to be_nil
        expect(change_position.diff_refs).to eq(change_diff_refs)

        attrs.each do |attr, value|
          expect(change_position.send(attr)).to eq(value)
        end
      end
    end
  end

  def create_branch(new_name, branch_name)
    CreateBranchService.new(project, current_user).execute(new_name, branch_name)
  end

  def create_file(branch_name, file_name, content)
    Files::CreateService.new(
      project,
      current_user,
      start_branch: branch_name,
      branch_name: branch_name,
      commit_message: "Create file",
      file_path: file_name,
      file_content: content
    ).execute
    project.commit(branch_name)
  end

  def update_file(branch_name, file_name, content)
    Files::UpdateService.new(
      project,
      current_user,
      start_branch: branch_name,
      branch_name: branch_name,
      commit_message: "Update file",
      file_path: file_name,
      file_content: content
    ).execute
    project.commit(branch_name)
  end

  def delete_file(branch_name, file_name)
    Files::DeleteService.new(
      project,
      current_user,
      start_branch: branch_name,
      branch_name: branch_name,
      commit_message: "Delete file",
      file_path: file_name
    ).execute
    project.commit(branch_name)
  end
end