]> source.dussan.org Git - redmine.git/commitdiff
Merged r14156 and r14161 (#19400).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Apr 2015 07:18:20 +0000 (07:18 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Apr 2015 07:18:20 +0000 (07:18 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@14198 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository.rb
test/functional/repositories_git_controller_test.rb
test/unit/repository_git_test.rb
test/unit/repository_test.rb

index a439e989e6ddbcb194b0c149d2c6511caa9f2b1f..5fc3bed44592d749c3ebb9716e1032b79048d75d 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
@@ -455,6 +456,10 @@ class Repository < ActiveRecord::Base
 
   protected
 
+  def normalize_identifier
+    self.identifier = identifier.to_s.strip
+  end
+
   def check_default
     if !is_default? && set_as_default?
       self.is_default = true
index 5e36ef6321caab63b8c342737a2b635dac02cedc..099e0d6d8c47906d8904dad1662fee5a3c921c4e 100644 (file)
@@ -265,7 +265,7 @@ class RepositoriesGitControllerTest < ActionController::TestCase
 
     def test_diff
       assert_equal true, @repository.is_default
-      assert_nil @repository.identifier
+      assert @repository.identifier.blank?
       assert_equal 0, @repository.changesets.count
       @repository.fetch_changesets
       @project.reload
index a7388d0f10f0304ca74193ca76fac865b0dd4106..f4e785af37256c40341ba93c64808fd8a64f26ae 100644 (file)
@@ -54,6 +54,8 @@ class RepositoryGitTest < ActiveSupport::TestCase
   end
 
   def test_nondefault_repo_with_blank_identifier_destruction
+    Repository.delete_all
+
     repo1 = Repository::Git.new(
                           :project    => @project,
                           :url        => REPOSITORY_PATH,
index 3ba36fd55136cd151f5b317abeb7c54e926ee220..6a530d4d323742e95b5706ce49926a81f9c25bd4 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),