Skip to content

Commit 94ec447

Browse files
authored
Use compact, not flatten, in the model registry (#6737)
`#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.
1 parent c571eda commit 94ec447

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/models/hyrax/model_registry.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def self.work_rdf_representations
9999
end
100100

101101
def self.classes_from(strings)
102-
strings.map(&:safe_constantize).flatten.uniq
102+
strings.map(&:safe_constantize).compact.uniq
103103
end
104104
private_class_method :classes_from
105105

spec/models/hyrax/model_registry_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@
2929
it { is_expected.to all(be_kind_of(String)) }
3030
end
3131
end
32+
33+
describe ".classes_from" do
34+
subject { described_class.send("classes_from", ["DefinitelyNotARealClass", "Hyrax"]) }
35+
36+
it { is_expected.to be_a(Array) }
37+
it { is_expected.not_to include(nil) }
38+
end
3239
end

0 commit comments

Comments
 (0)