From 6da097d91c9131ede95cf9dedf326cc078d667d3 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 26 May 2016 12:49:54 -0400 Subject: [PATCH] FIX: Deleted posts were showing the wrong dates in the timeline --- lib/timeline_lookup.rb | 4 ++-- spec/components/timeline_lookup_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/timeline_lookup.rb b/lib/timeline_lookup.rb index 4d4c3eac8..1c62d879f 100644 --- a/lib/timeline_lookup.rb +++ b/lib/timeline_lookup.rb @@ -11,10 +11,10 @@ module TimelineLookup tuples.each_with_index do |t, idx| next unless (idx % every) === 0 - _, post_number, days_ago = t + days_ago = t[2] if (days_ago != last_days_ago) - result << [post_number, days_ago] + result << [idx+1, days_ago] last_days_ago = days_ago end diff --git a/spec/components/timeline_lookup_spec.rb b/spec/components/timeline_lookup_spec.rb index 8cb5edc5b..3e1a2ef02 100644 --- a/spec/components/timeline_lookup_spec.rb +++ b/spec/components/timeline_lookup_spec.rb @@ -16,6 +16,11 @@ describe TimelineLookup do expect(result).to eq([[1, 10], [3, 8]]) end + it "respects holes in the post numbers" do + result = TimelineLookup.build([[111, 1, 10], [222, 12, 10], [333, 30, 8]]) + expect(result).to eq([[1, 10], [3, 8]]) + end + it "respects a `max_values` setting" do input = (1..100).map {|i| [1000+i, i, 100-i] }