summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-03-20 10:20:57 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-03-20 10:20:57 +0000
commite9caae140d531b79ae8b8055b0a132506afeff17 (patch)
tree40291eb05a448184fdea5d66ee7aca6fd51495d7
parentd5093417971b389a31a0aa58afe733e045025070 (diff)
downloadredmine-e9caae140d531b79ae8b8055b0a132506afeff17.tar.gz
redmine-e9caae140d531b79ae8b8055b0a132506afeff17.zip
Don't allow 2 repositories with blank identifier (#19400).
git-svn-id: http://svn.redmine.org/redmine/trunk@14142 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/repository.rb2
-rw-r--r--test/unit/repository_test.rb18
2 files changed, 19 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 475445ae5..83c5b7c5c 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -38,7 +38,7 @@ class Repository < ActiveRecord::Base
validates_length_of :password, :maximum => 255, :allow_nil => true
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
- validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true
+ validates_uniqueness_of :identifier, :scope => :project_id
validates_exclusion_of :identifier, :in => %w(browse show entry raw changes annotate diff statistics graph revisions revision)
# donwcase letters, digits, dashes, underscores but not digits only
validates_format_of :identifier, :with => /\A(?!\d+$)[a-z0-9\-_]*\z/, :allow_blank => true
diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb
index debac51b0..8f8cb9a0a 100644
--- a/test/unit/repository_test.rb
+++ b/test/unit/repository_test.rb
@@ -76,6 +76,24 @@ class RepositoryTest < ActiveSupport::TestCase
assert_equal repository, project.repository
end
+ def test_2_repositories_with_same_identifier_in_different_projects_should_be_valid
+ Repository::Subversion.create!(:project_id => 2, :identifier => 'foo', :url => 'file:///foo')
+ r = Repository::Subversion.new(:project_id => 3, :identifier => 'foo', :url => 'file:///bar')
+ assert r.save
+ end
+
+ def test_2_repositories_with_same_identifier_should_not_be_valid
+ Repository::Subversion.create!(:project_id => 3, :identifier => 'foo', :url => 'file:///foo')
+ r = Repository::Subversion.new(:project_id => 3, :identifier => 'foo', :url => 'file:///bar')
+ assert !r.save
+ end
+
+ def test_2_repositories_with_blank_identifier_should_not_be_valid
+ Repository::Subversion.create!(:project_id => 3, :identifier => '', :url => 'file:///foo')
+ r = Repository::Subversion.new(:project_id => 3, :identifier => '', :url => 'file:///bar')
+ assert !r.save
+ end
+
def test_first_repository_should_be_set_as_default
repository1 = Repository::Subversion.new(
:project => Project.find(3),