debian-mirror-gitlab/spec/models/clusters/agent_spec.rb

61 lines
1.8 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agent do
subject { create(:cluster_agent) }
it { is_expected.to belong_to(:project).class_name('::Project') }
it { is_expected.to have_many(:agent_tokens).class_name('Clusters::AgentToken') }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(63) }
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) }
2020-11-24 15:15:51 +05:30
describe 'scopes' do
2021-01-03 14:25:43 +05:30
describe '.ordered_by_name' do
let(:names) { %w(agent-d agent-b agent-a agent-c) }
subject { described_class.ordered_by_name }
before do
names.each do |name|
create(:cluster_agent, name: name)
end
end
it { expect(subject.map(&:name)).to eq(names.sort) }
end
2020-11-24 15:15:51 +05:30
describe '.with_name' do
let!(:matching_name) { create(:cluster_agent, name: 'matching-name') }
let!(:other_name) { create(:cluster_agent, name: 'other-name') }
subject { described_class.with_name(matching_name.name) }
it { is_expected.to contain_exactly(matching_name) }
end
end
2020-10-24 23:57:45 +05:30
describe 'validation' do
describe 'name validation' do
it 'rejects names that do not conform to RFC 1123', :aggregate_failures do
%w[Agent agentA agentAagain gent- -agent agent.a agent/a agent>a].each do |name|
agent = build(:cluster_agent, name: name)
expect(agent).not_to be_valid
expect(agent.errors[:name]).to eq(["can contain only lowercase letters, digits, and '-', but cannot start or end with '-'"])
end
end
it 'accepts valid names', :aggregate_failures do
%w[agent agent123 agent-123].each do |name|
agent = build(:cluster_agent, name: name)
expect(agent).to be_valid
end
end
end
end
end