Skip to content

Commit

Permalink
add new spec to ensure documents_for_lazy_attribute works with inline…
Browse files Browse the repository at this point in the history
… hash
  • Loading branch information
marcosgz committed Aug 7, 2024
1 parent 48d733b commit 6b4a582
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions spec/esse/repository/lazy_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,52 @@
)
repo.update_documents_attribute(:city_names, '2')
end

it 'updates the documents when passing a LazyDocumentHeader' do
header = Esse::LazyDocumentHeader.coerce(id: '2')
expect(repo.index).to receive(:bulk).with(
update: [
Esse::LazyDocumentHeader::Document.new(header, source: { city_names: 'London' })
]
)
repo.update_documents_attribute(:city_names, header)
end

it 'updates the documents when passing a single hash' do
expect(repo.index).to receive(:bulk).with(
update: [
Esse::LazyDocumentHeader.new(id: '2', admin: true).to_doc(city_names: 'London')
]
)
repo.update_documents_attribute(:city_names, {id: '2', admin: true})
end

it 'updates the documents when passing an array of ids' do
expect(repo.index).to receive(:bulk).with(
update: [
Esse::LazyDocumentHeader.new(id: '2').to_doc(city_names: 'London')
]
)
repo.update_documents_attribute(:city_names, ['2'])
end

it 'updates the documents when passing an array of LazyDocumentHeader' do
header = Esse::LazyDocumentHeader.coerce(id: '2')
expect(repo.index).to receive(:bulk).with(
update: [
Esse::LazyDocumentHeader::Document.new(header, source: { city_names: 'London' })
]
)
repo.update_documents_attribute(:city_names, [header])
end

it 'updates the documents when passing an array of hashes' do
expect(repo.index).to receive(:bulk).with(
update: [
Esse::LazyDocumentHeader.new(id: '2').to_doc(city_names: 'London')
]
)
repo.update_documents_attribute(:city_names, [{id: '2', admin: true}])
end
end
end

0 comments on commit 6b4a582

Please sign in to comment.