-
Notifications
You must be signed in to change notification settings - Fork 65
Fix invalid dates in feed ordering #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| require "test_helper" | ||
|
|
||
| class DateOrderingTest < Test::Unit::TestCase | ||
| def setup | ||
| @feed = SimpleRSS.parse(File.read(File.join(__dir__, "../data/mixed_dates.xml"))) | ||
| end | ||
|
|
||
| def test_latest_uses_valid_fallbacks_and_preserves_equal_date_order | ||
| assert_equal [ | ||
| "Updated first", "Updated second", "Fractional", "Published", "Publication", | ||
| "Historical", "Missing first", "Blank", "Invalid" | ||
|
cardmagic marked this conversation as resolved.
|
||
| ], @feed.latest.map(&:title) | ||
| end | ||
|
|
||
| def test_latest_limits_results_without_changing_original_entries | ||
| original = @feed.to_hash | ||
|
|
||
| assert_equal ["Updated first", "Updated second", "Fractional"], @feed.latest(3).map(&:title) | ||
|
cardmagic marked this conversation as resolved.
|
||
| assert_equal [], @feed.latest(0) | ||
| assert_same @feed.items[3], @feed.latest.first | ||
| assert_equal original, @feed.to_hash | ||
| end | ||
|
|
||
| def test_latest_sorts_atom_entries_with_only_published_dates | ||
| feed = SimpleRSS.parse <<~XML | ||
| <feed xmlns="http://www.w3.org/2005/Atom"> | ||
| <title>Publication dates</title> | ||
| <entry><title>Newer</title><published>2026-09-03T00:00:00Z</published></entry> | ||
| <entry><title>Older</title><published>2026-09-01T00:00:00Z</published></entry> | ||
| </feed> | ||
| XML | ||
|
|
||
| assert_equal %w[Newer Older], feed.latest.map(&:title) | ||
| end | ||
|
|
||
| def test_items_since_uses_valid_fallbacks_and_excludes_undated_entries | ||
| assert_equal ["Fractional", "Updated first", "Published", "Updated second"], | ||
|
cardmagic marked this conversation as resolved.
|
||
| @feed.items_since(Time.iso8601("2026-09-01T00:00:00Z")).map(&:title) | ||
|
cardmagic marked this conversation as resolved.
|
||
| assert_equal ["Fractional", "Updated first", "Updated second"], | ||
|
cardmagic marked this conversation as resolved.
|
||
| @feed.items_since(Time.iso8601("2026-09-02T00:00:00Z")).map(&:title) | ||
|
cardmagic marked this conversation as resolved.
|
||
| assert_equal [], @feed.items_since(Time.iso8601("2026-09-04T00:00:00Z")) | ||
|
cardmagic marked this conversation as resolved.
|
||
| end | ||
|
|
||
| def test_merge_sorts_dated_entries_before_undated_identified_entries | ||
| assert_equal [ | ||
| "Updated first", "Updated second", "Fractional", "Published", "Publication", | ||
|
cardmagic marked this conversation as resolved.
|
||
| "Historical", "Blank", "Invalid", "Missing first" | ||
|
cardmagic marked this conversation as resolved.
|
||
| ], @feed.merge.map(&:title) | ||
| end | ||
|
|
||
| def test_merge_uses_fallback_dates_to_dedupe_and_keeps_unidentified_entries_last | ||
|
cardmagic marked this conversation as resolved.
|
||
| other_feed = SimpleRSS.parse <<~XML | ||
| <rss version="2.0"> | ||
| <channel> | ||
| <title>Other feed</title> | ||
| <item> | ||
| <guid>updated-first</guid> | ||
| <title>Replacement</title> | ||
| <pubDate>not-a-date</pubDate> | ||
| <published>2026-09-04T00:00:00Z</published> | ||
| </item> | ||
| <item><title>Unidentified newest</title><pubDate>2030-01-01T00:00:00Z</pubDate></item> | ||
| </channel> | ||
| </rss> | ||
| XML | ||
| original = @feed.to_hash | ||
| other_original = other_feed.to_hash | ||
|
|
||
| assert_equal [ | ||
| "Replacement", "Updated second", "Fractional", "Published", "Publication", | ||
|
cardmagic marked this conversation as resolved.
|
||
| "Historical", "Blank", "Invalid", "Missing first", "Unidentified newest" | ||
|
cardmagic marked this conversation as resolved.
|
||
| ], SimpleRSS.merge(@feed, other_feed).map(&:title) | ||
| assert_equal original, @feed.to_hash | ||
| assert_equal other_original, other_feed.to_hash | ||
| end | ||
|
|
||
| def test_merge_keeps_the_first_duplicate_when_dates_are_equal | ||
|
cardmagic marked this conversation as resolved.
|
||
| other_feed = SimpleRSS.parse <<~XML | ||
| <rss version="2.0"> | ||
| <channel> | ||
| <title>Other feed</title> | ||
| <item> | ||
| <guid>updated-second</guid> | ||
| <title>Later duplicate</title> | ||
| <updated>2026-09-03T00:00:00.000000002Z</updated> | ||
| </item> | ||
| </channel> | ||
| </rss> | ||
| XML | ||
|
|
||
| duplicates = @feed.merge(other_feed).select { |item| item[:guid] == "updated-second" } | ||
|
cardmagic marked this conversation as resolved.
|
||
|
|
||
| assert_equal ["Updated second"], duplicates.map(&:title) | ||
|
cardmagic marked this conversation as resolved.
|
||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <rss version="2.0"> | ||
| <channel> | ||
| <title>Mixed dates</title> | ||
| <item> | ||
| <title>Missing first</title> | ||
| </item> | ||
| <item> | ||
| <guid>publication</guid> | ||
| <title>Publication</title> | ||
| <pubDate>2026-09-01T00:00:00Z</pubDate> | ||
| <updated>2026-09-05T00:00:00Z</updated> | ||
| <published>2026-09-06T00:00:00Z</published> | ||
| </item> | ||
| <item> | ||
| <guid>fractional</guid> | ||
| <title>Fractional</title> | ||
| <pubDate>2026-09-03T00:00:00.000000001Z</pubDate> | ||
| </item> | ||
| <item> | ||
| <guid>updated-first</guid> | ||
| <title>Updated first</title> | ||
| <pubDate>not-a-date</pubDate> | ||
| <updated>2026-09-03T00:00:00.000000002Z</updated> | ||
| <published>2026-09-07T00:00:00Z</published> | ||
| </item> | ||
| <item> | ||
| <guid>published</guid> | ||
| <title>Published</title> | ||
| <pubDate></pubDate> | ||
| <updated>not-a-date</updated> | ||
| <published>2026-09-02T00:00:00Z</published> | ||
| </item> | ||
| <item> | ||
| <guid>historical</guid> | ||
| <title>Historical</title> | ||
| <pubDate>1965-01-01T00:00:00Z</pubDate> | ||
| </item> | ||
| <item> | ||
| <guid>updated-second</guid> | ||
| <title>Updated second</title> | ||
| <updated>2026-09-03T01:00:00.000000002+01:00</updated> | ||
| </item> | ||
| <item> | ||
| <guid>blank</guid> | ||
| <title>Blank</title> | ||
| <pubDate> </pubDate> | ||
| </item> | ||
| <item> | ||
| <guid>invalid</guid> | ||
| <title>Invalid</title> | ||
| <pubDate>not-a-date</pubDate> | ||
| <updated>not-a-date</updated> | ||
| </item> | ||
| </channel> | ||
| </rss> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.