Skip to content

Commit

Permalink
Use compact, not flatten, in the model registry (#6737)
Browse files Browse the repository at this point in the history
`#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.
  • Loading branch information
marrus-sh authored Mar 11, 2024
1 parent c571eda commit 94ec447
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/hyrax/model_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions spec/models/hyrax/model_registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 94ec447

Please sign in to comment.