From 94ec4472aedf87440c2828f6036d7e2ea75fee9d Mon Sep 17 00:00:00 2001 From: kibigo! Date: Mon, 11 Mar 2024 10:32:20 -0400 Subject: [PATCH] Use compact, not flatten, in the model registry (#6737) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `#safe_constantize` shouldn’t ever return an Array, so there shouldn’t be any need for flattening. It may, however, return `nil`. `#compact` will get rid of that, and likely is what was intended here. --- app/models/hyrax/model_registry.rb | 2 +- spec/models/hyrax/model_registry_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/hyrax/model_registry.rb b/app/models/hyrax/model_registry.rb index 6e6e219e2c..b11550edb7 100644 --- a/app/models/hyrax/model_registry.rb +++ b/app/models/hyrax/model_registry.rb @@ -99,7 +99,7 @@ def self.work_rdf_representations end def self.classes_from(strings) - strings.map(&:safe_constantize).flatten.uniq + strings.map(&:safe_constantize).compact.uniq end private_class_method :classes_from diff --git a/spec/models/hyrax/model_registry_spec.rb b/spec/models/hyrax/model_registry_spec.rb index 6eb31ab287..567fd2f784 100644 --- a/spec/models/hyrax/model_registry_spec.rb +++ b/spec/models/hyrax/model_registry_spec.rb @@ -29,4 +29,11 @@ it { is_expected.to all(be_kind_of(String)) } end end + + describe ".classes_from" do + subject { described_class.send("classes_from", ["DefinitelyNotARealClass", "Hyrax"]) } + + it { is_expected.to be_a(Array) } + it { is_expected.not_to include(nil) } + end end