diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c1a60d56..aff74b82b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ * [#874](https://github.com/toptal/chewy/pull/874): Fix `chewy:journal:clean` task for ruby 3.x. ([@muk-ai](https://github.com/muk-ai)) * [#882](https://github.com/toptal/chewy/pull/882): Fix memory leak during `chewy:reset` for ruby 3.2 ([@konalegi](https://github.com/konalegi)) +* [#861](https://github.com/toptal/chewy/pull/861): Fix bug in mock_elasticsearch_response_sources ([@lafeber](https://github.com/lafeber)) + ## 7.3.0 (2023-04-03) ### New Features diff --git a/lib/chewy/minitest/helpers.rb b/lib/chewy/minitest/helpers.rb index 26ff95e3f..e9fbd1362 100644 --- a/lib/chewy/minitest/helpers.rb +++ b/lib/chewy/minitest/helpers.rb @@ -97,7 +97,7 @@ def mock_elasticsearch_response_sources(index, hits, &block) { '_index' => index.index_name, '_type' => '_doc', - '_id' => (i + 1).to_s, + '_id' => hit[:id] || (i + 1).to_s, '_score' => 3.14, '_source' => hit } diff --git a/spec/chewy/minitest/helpers_spec.rb b/spec/chewy/minitest/helpers_spec.rb index 98fd0f08e..41353b928 100644 --- a/spec/chewy/minitest/helpers_spec.rb +++ b/spec/chewy/minitest/helpers_spec.rb @@ -32,14 +32,14 @@ def assert_equal(expected, actual, message) { '_index' => 'dummies', '_type' => '_doc', - '_id' => '1', + '_id' => '2', '_score' => 3.14, '_source' => source } ] end - let(:source) { {'name' => 'some_name'} } + let(:source) { {'name' => 'some_name', id: '2'} } let(:sources) { [source] } context 'mocks by raw response' do