Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: freerange/jam-coop
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 66f9219e80b3c114d11c53b2bb437c5f132988b9
Choose a base ref
..
head repository: freerange/jam-coop
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d918ccca6ee70b51325b8dbc8012ae053305658d
Choose a head ref
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ gem 'rails_autolink', '~> 1.1'
gem 'redcarpet', '~> 3.6'
gem 'redis', '~> 5.0'
gem 'rollbar'
gem 'rss'
gem 'rubyzip', '~> 2.3'
gem 'sidekiq'
gem 'sprockets-rails'
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -288,6 +288,8 @@ GEM
io-console (~> 0.5)
rexml (3.2.6)
rollbar (3.4.2)
rss (0.3.0)
rexml
rubocop (1.59.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
@@ -391,6 +393,7 @@ DEPENDENCIES
redcarpet (~> 3.6)
redis (~> 5.0)
rollbar
rss
rubocop-capybara
rubocop-factory_bot
rubocop-rails
17 changes: 17 additions & 0 deletions app/views/artists/index.atom.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

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'
f.updated artists.first.updated_at
artists.each do |artist|
id = "tag:#{request.host},2024:#{artist_path(artist)}"
published = artist.first_listed_on
f.entry(artist, id:, published:) do |e|
e.title artist.name
e.author { |a| a.name 'jam.coop' }
e.content artist.description, type: 'html'
end
end
end
4 changes: 4 additions & 0 deletions app/views/artists/index.html.erb
Original file line number Diff line number Diff line change
@@ -4,6 +4,10 @@
)
%>

<% content_for(:auto_discovery) do %>
<%= auto_discovery_link_tag(:atom, { format: :atom }, { title: 'Artists on jam.coop' }) %>
<% end %>

<%= render('shared/page_header', text: 'Artists') %>

<div class="pt-4 grid grid-cols-3 gap-4">
18 changes: 18 additions & 0 deletions app/views/artists/show.atom.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

albums = @albums.in_release_order

atom_feed(language: 'en-GB', schema_date: 2024) do |f|
f.title "#{@artist.name} albums on jam.coop"
f.updated albums.first.released_on
albums.each do |album|
id = "tag:#{request.host},2024:#{artist_album_path(@artist, album)}"
url = artist_album_url(@artist, album)
published = album.released_on
f.entry(album, id:, url:, published:) do |e|
e.title album.title
e.author { |a| a.name @artist.name }
e.content format_metadata(album.about), type: 'html'
end
end
end
4 changes: 4 additions & 0 deletions app/views/artists/show.html.erb
Original file line number Diff line number Diff line change
@@ -5,6 +5,10 @@
)
%>

<% content_for(:auto_discovery) do %>
<%= auto_discovery_link_tag(:atom, { format: :atom }, { title: "#{@artist.name} albums on jam.coop" }) %>
<% end %>

<div class="flex flex-row border-b-2 border-b-slate-100 pb-6">
<div class="basis-1/4 mr-4 m:mr-0">
<div class="aspect-w-1 aspect-h-1">
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
<%= hotwire_livereload_tags if Rails.env.development? %>
<%= content_for(:auto_discovery) %>
</head>

<body class="bg-slate-100">
70 changes: 70 additions & 0 deletions test/controllers/artists_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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)

@@ -142,6 +162,33 @@ class ArtistsControllerTestSignedOut < ActionDispatch::IntegrationTest
assert_select 'p', { text: @artist.name }
end

test '#index includes auto-discovery link for atom feed' do
get artists_url

url = artists_url(format: :atom)
assert_select "head link[rel='alternate'][type='application/atom+xml'][href='#{url}']"
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)

@@ -166,6 +213,29 @@ class ArtistsControllerTestSignedOut < ActionDispatch::IntegrationTest
assert_select 'p', { text: 'Album Title (pending)', count: 0 }
end

test '#show includes auto-discovery link for atom feed' do
get artist_url(@artist)

url = artist_url(@artist, format: :atom)
assert_select "head link[rel='alternate'][type='application/atom+xml'][href='#{url}']"
end

test '#show with atom format should render atom feed' do
@artist.albums << create(:album, title: 'Older', publication_status: :published, released_on: 2.days.ago)
@artist.albums << create(:album, title: 'Newer', publication_status: :published, released_on: 1.day.ago)
@artist.albums << create(:album, title: 'Pending', publication_status: :pending, released_on: 0.days.ago)
@artist.albums << create(:album, title: 'Unpublished', publication_status: :unpublished, released_on: 0.days.ago)

get artist_url(@artist, format: :atom)

feed = RSS::Parser.parse(response.body)
assert_equal "#{@artist.name} albums on jam.coop", feed.title.content
assert_equal 'Newer', feed.entries.first.title.content
assert_equal 'Older', feed.entries.last.title.content
assert_not_includes feed.entries.map(&:title).map(&:content), 'Pending'
assert_not_includes feed.entries.map(&:title).map(&:content), 'Unpublished'
end

test '#new' do
get new_artist_url
assert_redirected_to log_in_path