Commit baad39eb authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Project model: validation of vcs_type

This is simply ensuring the value is a support type

We're testing this twice (model and service) because `project_spec`
is not yet in the Heptapod CI shortlist and it takes too much time
that such a trivial test would be worth it. Of course, it has
its intrinsic value, and we will activate it soonish, but that's not
the current concern. Also this prepares for potentially more advanced
behaviour at the service level.

--HG--
branch : heptapod
parent 8138abfc04d1
......@@ -405,6 +405,8 @@ class Project < ApplicationRecord
# Validations
validates :creator, presence: true, on: :create
validates :vcs_type, presence: false,
inclusion: { in: Gitlab::VCS::SUPPORTED_TYPES }
validates :description, length: { maximum: 2000 }, allow_blank: true
validates :ci_config_path,
format: { without: %r{(\.{2}|\A/)},
......
......@@ -251,6 +251,9 @@
it { is_expected.to validate_length_of(:description).is_at_most(2000) }
it { is_expected.to validate_length_of(:ci_config_path).is_at_most(255) }
it { is_expected.to allow_value('').for(:ci_config_path) }
it { is_expected.to allow_value('git').for(:vcs_type) }
# let's hope we are never crazy enough to try and support CVS
it { is_expected.not_to allow_value('cvs').for(:vcs_type) }
it { is_expected.not_to allow_value('test/../foo').for(:ci_config_path) }
it { is_expected.not_to allow_value('/test/foo').for(:ci_config_path) }
it { is_expected.to validate_presence_of(:creator) }
......
......@@ -668,6 +668,42 @@ def wiki_repo(project)
end
end
context 'with invalid vcs_type' do
before do
# It's safe to bet that we won't be crazy enough to support CVS
opts.merge!(
vcs_type: 'cvs',
)
end
it 'refuses to create the project' do
project = create_project(user, opts)
expect(project).to respond_to(:errors)
expect(project.errors.any?).to be(true)
expect(project.saved?).to be_falsey
expect(project.valid?).to be_falsey
expect(project.errors.messages).to have_key(:vcs_type)
end
end
context 'with valid vcs_type' do
before do
opts.merge!(
vcs_type: 'git',
)
end
it 'creates the project' do
project = create_project(user, opts)
expect(project).to respond_to(:errors)
expect(project.errors.any?).to be_falsey
expect(project.saved?).to be(true)
expect(project.valid?).to be(true)
expect(project.vcs_type).to eq('git')
end
end
context 'with Heptapod rules for external users' do
let_it_be(:ext_user) { create(:user, :external) }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment