From 1154fd33bfeb94aa01bdd7b3a9ac94b521f3ae62 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 21 Mar 2015 08:29:59 +0000 Subject: [PATCH] Merged r14142 and r14143 (#19400). git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@14148 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/repository.rb | 2 +- app/models/repository/git.rb | 4 ++-- test/unit/repository_test.rb | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 36ed06b7f..a439e989e 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 474032a07..b9ac27732 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 458d8ac53..3ba36fd55 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), -- 2.39.5