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
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