A small service builds a preview window from an input event enumerator. After a recent change, the preview started behaving inconsistently: some items may disappear, and the result depends on whether a preliminary check for available data was performed.
FeedPreview.build method accepts events: and limit:.events is any object that responds to each and yields hashes of the form { id:, title:, published: }.published is true must be included in the result.items — an array of strings of the form "ID TITLE";has_more — true if there is at least one more published event after the selected window.events is an array or a one-time enumerator.require_relative "feed_preview"
stream = Enumerator.new do |y|
y << { id: 1, title: "Draft", published: false }
y << { id: 2, title: "Alpha", published: true }
y << { id: 3, title: "Beta", published: true }
y << { id: 4, title: "Gamma", published: true }
end
p FeedPreview.build(events: stream, limit: 2)
items for the first two published events: "2 Alpha" and "3 Beta".has_more should be true because there is one more published event after the window.Enumerator with the same events.items must not contain nil or empty elements, even if some of the first records are unpublished events.3.3ruby demo.rb or a direct FeedPreview.build call:id, :title, :publishedUse line comments to explain the problem, its impact, the fix and how to test it.