summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-06-22 16:39:16 +0200
committerJames Lopez <james@jameslopez.es>2016-06-22 16:39:16 +0200
commit48d76ecec8ec0387db4fbbda3f065c424c3ea51a (patch)
tree3c20f6a5d53fe5f1199036de6ed498eea242ca3d
parent26b612258fe4223a91403e6414cb3f5897e2dd5e (diff)
downloadgitlab-ce-48d76ecec8ec0387db4fbbda3f065c424c3ea51a.tar.gz
another fix and fixed spec
-rw-r--r--app/models/project.rb2
-rw-r--r--spec/models/project_spec.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index ceebfcd733b..64c1722ccf0 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -447,6 +447,8 @@ class Project < ActiveRecord::Base
import_url = Gitlab::UrlSanitizer.new(value)
create_or_update_import_data(credentials: import_url.credentials)
super(import_url.sanitized_url)
+ rescue Addressable::URI::InvalidURIError
+ errors.add(:import_url, 'must be a valid URL.')
end
def import_url
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 897b6898f54..5859691a3c4 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -65,7 +65,14 @@ describe Project, models: true do
end
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
end
end