2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe RunnerEntity do
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:runner) { create(:ci_runner, :project, projects: [project]) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:entity) { described_class.new(runner, request: request, current_user: user) }
|
|
|
|
let(:request) { double('request') }
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:user) { project.first_owner }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
|
|
|
allow(request).to receive(:project).and_return(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#as_json' do
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
it 'contains required fields' do
|
|
|
|
expect(subject).to include(:id, :description)
|
|
|
|
expect(subject).to include(:edit_path)
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(subject).to include(:short_sha)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2023-07-09 08:55:56 +05:30
|
|
|
|
|
|
|
context 'without admin permissions' do
|
|
|
|
it 'does not contain admin_path field' do
|
|
|
|
expect(subject).not_to include(:admin_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with admin permissions' do
|
|
|
|
let_it_be(:user) { create(:user, :admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(user).to receive(:can_admin_all_resources?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains admin_path field' do
|
|
|
|
expect(subject).to include(:admin_path)
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|