A platform for community discussion. Free, open, simple.
FIX: ensures timeline_lookup includes last tuple (#11829)
Joffrey JAFFEUX8edd2b38cb29
diff --git a/lib/timeline_lookup.rb b/lib/timeline_lookup.rbindex 2e6cf57c82b..f477153f947 100644--- a/lib/timeline_lookup.rb+++ b/lib/timeline_lookup.rb@@ -12,7 +12,10 @@ module TimelineLookuplast_days_ago = -1tuples.each_with_index do |t, idx|return result unless t.is_a?(Array)- next unless (idx % every) === 0++ if idx != tuples.size - 1+ next unless (idx % every) === 0+ enddays_ago = t[1]diff --git a/spec/lib/timeline_lookup_spec.rb b/spec/lib/timeline_lookup_spec.rbnew file mode 100644index 00000000000..517b038c57e--- /dev/null+++ b/spec/lib/timeline_lookup_spec.rb@@ -0,0 +1,17 @@+# frozen_string_literal: true++require 'rails_helper'++describe TimelineLookup do++ context '.build' do+ it 'keeps the last tuple in the lookup' do+ tuples = [+ [7173, 400], [7174, 390], [7175, 380], [7176, 370], [7177, 1]+ ]++ expect(TimelineLookup.build(tuples, 2)).to eq([[1, 400], [4, 370], [5, 1]])+ end+ end++end