Skip to content

Commit

Permalink
Merge pull request #5540 from avalonmediasystem/empty_playlist_manifests
Browse files Browse the repository at this point in the history
Manifest should still generate when playlist is empty
  • Loading branch information
cjcolvar authored Dec 20, 2023
2 parents 6480ea5 + d22e46a commit 6563b68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/playlists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def manifest

# Fetch all master files related to the playlist items in a single SpeedyAF::Base.where
master_file_ids = @playlist.items.collect { |item| item.clip.master_file_id }
master_files = SpeedyAF::Proxy::MasterFile.where("id:#{master_file_ids.join(' id:')}", load_reflections: true)
master_files = []
master_files = SpeedyAF::Proxy::MasterFile.where("id:#{master_file_ids.join(' id:')}", load_reflections: true) if master_file_ids.present?
media_objects = master_files.collect(&:media_object).uniq(&:id)

# This small optimization relies on the assumption that can? :read, master_file is the same as can? :read, master_file.media_object
Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/playlists_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,19 @@
expect(parsed_response['items'][0]['metadata']).to be_present
end

context "when playlist is empty" do
let(:playlist) { FactoryBot.create(:playlist, items: [], visibility: Playlist::PUBLIC) }

it "returns a IIIF manifest" do
get :manifest, format: 'json', params: { id: playlist.id }, session: valid_session
expect(response).to have_http_status(200)
parsed_response = JSON.parse(response.body)
expect(parsed_response['@context']).to include "http://iiif.io/api/presentation/3/context.json"
expect(parsed_response['type']).to eq 'Manifest'
expect(parsed_response['items']).to be_empty
end
end

context "when playlist owner" do
before do
login_user playlist.user.user_key
Expand Down

0 comments on commit 6563b68

Please sign in to comment.