From: Jean-Philippe Lang Date: Sun, 4 Sep 2016 17:12:18 +0000 (+0000) Subject: Merged r15816 (#23758). X-Git-Tag: 3.1.7~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e0b3f5f671db48b57000f086007ce93d1f2661a1;p=redmine.git Merged r15816 (#23758). git-svn-id: http://svn.redmine.org/redmine/branches/3.1-stable@15819 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/repository.rb b/app/models/repository.rb index be1ea93d9..8276bef34 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -363,10 +363,14 @@ class Repository < ActiveRecord::Base end def self.factory(klass_name, *args) - klass = "Repository::#{klass_name}".constantize - klass.new(*args) - rescue - nil + repository_class(klass_name).new(*args) rescue nil + end + + def self.repository_class(class_name) + class_name = class_name.to_s.classify + if Redmine::Scm::Base.all.include?(class_name) + "Repository::#{class_name}".constantize + end end def self.scm_adapter_class diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 238c29d64..da3273ead 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -496,4 +496,18 @@ class RepositoryTest < ActiveSupport::TestCase Repository::Subversion.any_instance.expects(:fetch_changesets).twice.returns(true) Repository.fetch_changesets end + + def test_repository_class + assert_equal Repository::Subversion, Repository.repository_class('Subversion') + assert_equal Repository::Git, Repository.repository_class('Git') + assert_nil Repository.factory('Serializer') + assert_nil Repository.factory('Query') + end + + def test_factory + assert_instance_of Repository::Subversion, Repository.factory('Subversion') + assert_instance_of Repository::Git, Repository.factory('Git') + assert_nil Repository.factory('Serializer') + assert_nil Repository.factory('Query') + end end