debian-mirror-gitlab/spec/validators/project_path_validator_spec.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ProjectPathValidator do
2018-03-17 18:26:18 +05:30
let(:validator) { described_class.new(attributes: [:path]) }
describe '.valid_path?' do
it 'handles invalid utf8' do
2019-12-21 20:55:43 +05:30
expect(described_class.valid_path?(+"a\0weird\255path")).to be_falsey
2018-03-17 18:26:18 +05:30
end
end
describe '#validates_each' do
it 'adds a message when the path is not in the correct format' do
project = build(:project)
validator.validate_each(project, :path, "Path with spaces, and comma's!")
expect(project.errors[:path]).to include(Gitlab::PathRegex.project_path_format_message)
end
it 'adds a message when the path is reserved when creating' do
project = build(:project, path: 'blob')
validator.validate_each(project, :path, 'blob')
expect(project.errors[:path]).to include('blob is a reserved name')
end
it 'adds a message when the path is reserved when updating' do
project = create(:project)
project.path = 'blob'
validator.validate_each(project, :path, 'blob')
expect(project.errors[:path]).to include('blob is a reserved name')
end
end
end