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

api_service_spec.rb « protected_branches « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 94484f5a7b9bd3e913814604b3c4f428858ebd1c (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ProtectedBranches::ApiService do
  let_it_be(:project) { create(:project) }
  let_it_be(:user) { create(:user, maintainer_projects: [project]) }

  it 'creates a protected branch with prefilled defaults' do
    expect(::ProtectedBranches::CreateService).to receive(:new).with(
      project, user, hash_including(
                       push_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }],
                       merge_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }]
                     )
    ).and_call_original

    expect(described_class.new(project, user, { name: 'new name' }).create).to be_valid
  end

  it 'updates a protected branch without prefilled defaults' do
    protected_branch = create(:protected_branch, project: project, allow_force_push: true)

    expect(::ProtectedBranches::UpdateService).to receive(:new).with(
      project, user, hash_including(
                       push_access_levels_attributes: [],
                       merge_access_levels_attributes: []
                     )
    ).and_call_original

    expect do
      expect(described_class.new(project, user, { name: 'new name' }).update(protected_branch)).to be_valid
    end.not_to change { protected_branch.reload.allow_force_push }
  end
end