]> source.dussan.org Git - redmine.git/commitdiff
Fixed that 2 repositories can be created with blank/nil identifier (#19400).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 11 Apr 2015 06:27:54 +0000 (06:27 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 11 Apr 2015 06:27:54 +0000 (06:27 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14156 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository.rb
test/unit/repository_test.rb

index 83c5b7c5cf4ec1ea1b49c550f781929beb27c019..3a911cd5d55069be0b7cbda5f833b022506fad96 100644 (file)
@@ -30,6 +30,7 @@ class Repository < ActiveRecord::Base
 
   serialize :extra_info
 
+  before_validation :normalize_identifier
   before_save :check_default
 
   # Raw SQL to delete changesets and changes in the database
@@ -469,6 +470,10 @@ class Repository < ActiveRecord::Base
     end
   end
 
+  def normalize_identifier
+    self.identifier = identifier.to_s.strip
+  end
+
   def check_default
     if !is_default? && set_as_default?
       self.is_default = true
index 8f8cb9a0a405284b59b19b5b8406a681dcbd07bd..daa859b3bfbbc1cec1434db5e143743e2c20c734 100644 (file)
@@ -94,6 +94,18 @@ class RepositoryTest < ActiveSupport::TestCase
     assert !r.save
   end
 
+  def test_2_repositories_with_blank_identifier_and_one_as_default_should_not_be_valid
+    Repository::Subversion.create!(:project_id => 3, :identifier => '', :url => 'file:///foo', :is_default => true)
+    r = Repository::Subversion.new(:project_id => 3, :identifier => '', :url => 'file:///bar')
+    assert !r.save
+  end
+
+  def test_2_repositories_with_blank_and_nil_identifier_should_not_be_valid
+    Repository::Subversion.create!(:project_id => 3, :identifier => nil, :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),