another fix and fixed spec

This commit is contained in:
James Lopez 2016-06-22 16:39:16 +02:00
parent 26b612258f
commit 48d76ecec8
2 changed files with 10 additions and 1 deletions

View file

@ -447,6 +447,8 @@ class Project < ActiveRecord::Base
import_url = Gitlab::UrlSanitizer.new(value) import_url = Gitlab::UrlSanitizer.new(value)
create_or_update_import_data(credentials: import_url.credentials) create_or_update_import_data(credentials: import_url.credentials)
super(import_url.sanitized_url) super(import_url.sanitized_url)
rescue Addressable::URI::InvalidURIError
errors.add(:import_url, 'must be a valid URL.')
end end
def import_url def import_url

View file

@ -65,7 +65,14 @@ describe Project, models: true do
end end
it 'should not allow an invalid URI as import_url' do it 'should not allow an invalid URI as import_url' do
project2 = build(:project) project2 = build(:project, import_url: 'invalid://')
expect(project2).not_to be_valid
end
it 'should allow a valid URI as import_url' do
project2 = build(:project, import_url: 'ssh://test@gitlab.com/project.git')
expect(project2).to be_valid expect(project2).to be_valid
end end
end end