From 31da226bd6309b6ed004af28b8ac8ace30cf04c7 Mon Sep 17 00:00:00 2001 From: Sergio Bobillier Date: Fri, 12 Dec 2025 13:57:16 +0100 Subject: [PATCH] [BUGFIX] Revert 9291f29 "[JAY-639] Fix PropertiesFetcher#last" The commit being reverted was supposed to fix an issue in the PropertiesFetcher class's #last method, however, that issue never existed to begin with. The argument for the fix was that #last was sorting in descending order and then taking the last, which would effectively return the first, however, that is not true, because it is also asking Elasticsearch for a single document (by calling #size with its parameter set to 1). Hence, Elasticsearch would return a single document, the last entry in the index (ordered chronologically). So the logic was correct to begin with. This fixes the issue by reverting the changes introduced by #11 --- CHANGELOG.md | 4 ++++ lib/jay_api/properties_fetcher.rb | 2 +- spec/jay_api/properties_fetcher_spec.rb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93e7cec..4854f35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ Please mark backwards incompatible changes with an exclamation mark at the start ## [Unreleased] +### Fixed +- `PropertiesFetcher#last` now correctly returns the last set of properties + (ordered chronologically). + ## [29.3.0] - 2025-12-11 ### Added diff --git a/lib/jay_api/properties_fetcher.rb b/lib/jay_api/properties_fetcher.rb index 8266a19..133d5b0 100644 --- a/lib/jay_api/properties_fetcher.rb +++ b/lib/jay_api/properties_fetcher.rb @@ -129,7 +129,7 @@ def and # @return [Hash, nil] The last set of properties (ordered chronologically) # or +nil+ if no properties are found. def last - sort_records('asc').size(1) + sort_records('desc').size(1) fetch_properties.last end diff --git a/spec/jay_api/properties_fetcher_spec.rb b/spec/jay_api/properties_fetcher_spec.rb index 257a51e..b3e49cb 100644 --- a/spec/jay_api/properties_fetcher_spec.rb +++ b/spec/jay_api/properties_fetcher_spec.rb @@ -347,7 +347,7 @@ shared_examples_for '#last' do it 'adds a sorting clause to the query' do - expect(query_builder).to receive(:sort).with('timestamp' => 'asc') + expect(query_builder).to receive(:sort).with('timestamp' => 'desc') method_call end