summaryrefslogtreecommitdiff
path: root/spec/services/ci/runners/assign_runner_service_spec.rb
blob: 00b176bb759ec5b3f1d53435ee2130c964fe9b00 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::Ci::Runners::AssignRunnerService, '#execute' do
  subject { described_class.new(runner, project, user).execute }

  let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) }
  let_it_be(:project) { create(:project) }

  context 'without user' do
    let(:user) { nil }

    it 'does not call assign_to on runner and returns false' do
      expect(runner).not_to receive(:assign_to)

      is_expected.to eq(false)
    end
  end

  context 'with unauthorized user' do
    let(:user) { build(:user) }

    it 'does not call assign_to on runner and returns false' do
      expect(runner).not_to receive(:assign_to)

      is_expected.to eq(false)
    end
  end

  context 'with admin user', :enable_admin_mode do
    let(:user) { create_default(:user, :admin) }

    it 'calls assign_to on runner and returns value unchanged' do
      expect(runner).to receive(:assign_to).with(project, user).once.and_return('assign_to return value')

      is_expected.to eq('assign_to return value')
    end
  end
end