Skip to content

Commit

Permalink
Only include listed artists in Atom feed even for admins
Browse files Browse the repository at this point in the history
This improves the test coverage for the artists Atom feed and fixes the
problem that caused this exception [1]:

    ActionView::Template::Error: comparison of Date with nil failed

This probably wasn't a serious issue, because most feed readers would
not be signed in.

The fix works because all listed artists should have a value for
`Artist#first_listed_on`.

[1]: https://app.rollbar.com/a/gofreerange/fix/item/jam/45
  • Loading branch information
floehopper committed Jan 9, 2024
1 parent f4d3101 commit 4e31a4a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/views/artists/index.atom.builder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

artists = @artists.sort_by(&:first_listed_on).reverse
artists = @artists.listed.sort_by(&:first_listed_on).reverse

atom_feed(root_url: artists_url, language: 'en-GB', schema_date: 2024) do |f|
f.title 'Artists on jam.coop'
Expand Down
28 changes: 25 additions & 3 deletions test/controllers/artists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ class ArtistsControllerTestSignedIn < ActionDispatch::IntegrationTest
assert_select 'p', @artist.name
end

test '#index with atom format should render atom feed' do
@artist.update!(name: 'Older Artist')
create(:album, artist: @artist, first_published_on: 3.days.ago)
create(:album, artist: @artist, publication_status: :unpublished)

another_artist = create(:artist, name: 'Newer Artist')
create(:album, artist: another_artist, first_published_on: 1.day.ago)

unlisted_artist = create(:artist, name: 'Unlisted Artist')
create(:album, artist: unlisted_artist, publication_status: :unpublished)

get artists_url(format: :atom)

feed = RSS::Parser.parse(response.body)
assert_equal 'Artists on jam.coop', feed.title.content
assert_equal 'Newer Artist', feed.entries.first.title.content
assert_equal 'Older Artist', feed.entries.last.title.content
assert_not_includes feed.entries.map(&:title).map(&:content), 'Unlisted Artist'
end

test '#show should include published albums' do
@artist.albums << create(:album, title: 'Album Title', publication_status: :published)

Expand Down Expand Up @@ -151,12 +171,14 @@ class ArtistsControllerTestSignedOut < ActionDispatch::IntegrationTest

test '#index with atom format should render atom feed' do
@artist.update!(name: 'Older Artist')
@artist.albums << create(:album, publication_status: :published)
create(:album, artist: @artist, first_published_on: 3.days.ago)
create(:album, artist: @artist, publication_status: :unpublished)

another_artist = create(:artist, name: 'Newer Artist')
another_artist.albums << create(:album, publication_status: :published)
create(:album, artist: another_artist, first_published_on: 1.day.ago)

create(:artist, name: 'Unlisted Artist')
unlisted_artist = create(:artist, name: 'Unlisted Artist')
create(:album, artist: unlisted_artist, publication_status: :unpublished)

get artists_url(format: :atom)

Expand Down

0 comments on commit 4e31a4a

Please sign in to comment.