From: Jean-Philippe Lang Date: Sat, 21 Mar 2015 08:26:22 +0000 (+0000) Subject: Merged r14142 and r14143 (#19400). X-Git-Tag: 3.0.2~27 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c6c304edf1e399b0669424bf011ea40a4217556e;p=redmine.git Merged r14142 and r14143 (#19400). git-svn-id: http://svn.redmine.org/redmine/branches/3.0-stable@14147 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/repository.rb b/app/models/repository.rb index 21e97bb6e..472bf615b 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/app/models/repository/git.rb b/app/models/repository/git.rb index 18797315f..c71801f2c 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -209,7 +209,7 @@ class Repository::Git < Repository end h["heads"] = repo_heads.dup merge_extra_info(h) - self.save + save(:validate => false) end private :save_revisions @@ -251,7 +251,7 @@ class Repository::Git < Repository h = {} h["extra_report_last_commit"] = v merge_extra_info(h) - self.save + save(:validate => false) end private :clear_extra_info_of_changesets end 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),