OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
use hash mapping name to class instead of storing just names
Ivan Kuchinddf0dc2a532d
diff --git a/lib_static/open_project/acts/registry_methods.rb b/lib_static/open_project/acts/registry_methods.rbindex ff0f275d370..ae9632baba0 100644--- a/lib_static/open_project/acts/registry_methods.rb+++ b/lib_static/open_project/acts/registry_methods.rb@@ -30,9 +30,7 @@ module OpenProjectmodule Actsmodule RegistryMethodsdef instance(model_name)- class_name = model_name.singularize.camelize-- class_name.constantize if class_names.include?(class_name)+ models[model_name.singularize.camelize]enddef add(*models)@@ -44,14 +42,14 @@ module OpenProjectraise ArgumentError.new("Model #{model} does not include #{acts_as_method_name}")end- class_names << model.name+ self.models[model.name] = modelendendprivate- def class_names- @class_names ||= Set.new+ def models+ @models ||= Hash.newendendenddiff --git a/spec/lib/acts_as_watchable/lib/open_project/acts/registry_methods_spec.rb b/spec/lib/acts_as_watchable/lib/open_project/acts/registry_methods_spec.rbindex 94bb1fb687f..da6caeaae62 100644--- a/spec/lib/acts_as_watchable/lib/open_project/acts/registry_methods_spec.rb+++ b/spec/lib/acts_as_watchable/lib/open_project/acts/registry_methods_spec.rb@@ -58,8 +58,6 @@ RSpec.describe OpenProject::Acts::RegistryMethods dodescribe ".instance" dobefore domodel.include instance_methods_module-- allow(ActiveSupport::Inflector).to receive(:constantize).with("Model").and_return(model)endit "returns nil for non registered model" do@@ -71,5 +69,22 @@ RSpec.describe OpenProject::Acts::RegistryMethods doexpect(registry.instance("models")).to eq(model)end++ describe "after model reload" do+ let(:reloaded_model) { Class.new }++ before do+ reloaded_model.include instance_methods_module++ allow(reloaded_model).to receive(:name).and_return("Model")++ registry.add(model)+ registry.add(reloaded_model)+ end++ it "returns reloaded model class" do+ expect(registry.instance("models")).to eq(reloaded_model)+ end+ endendend