Skip to content

Commit

Permalink
fix: flatten array on lazy header coerce each
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Aug 8, 2024
1 parent 0a9bf46 commit 4092de5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/esse/lazy_document_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Esse
class LazyDocumentHeader
def self.coerce_each(values)
arr = []
Esse::ArrayUtils.wrap(values).map do |value|
Esse::ArrayUtils.wrap(values).flatten.map do |value|
instance = coerce(value)
arr << instance if instance&.valid?
end
Expand Down
4 changes: 4 additions & 0 deletions spec/esse/lazzy_document_header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@
it 'removes invalid instances' do
expect(described_class.coerce_each([nil, {_id: 1}, {}]).size).to eq(1)
end

it 'flattens the array' do
expect(described_class.coerce_each([[{_id: 1}], {_id: 2}]).size).to eq(2)
end
end

describe '#to_doc' do
Expand Down

0 comments on commit 4092de5

Please sign in to comment.