diff --git a/app/controllers/api/playlists_controller.rb b/app/controllers/api/playlists_controller.rb index 23e08af..1a7c2a5 100644 --- a/app/controllers/api/playlists_controller.rb +++ b/app/controllers/api/playlists_controller.rb @@ -1,6 +1,6 @@ module API class PlaylistsController < ApplicationController - before_action :set_playlist, only: %i[show update] + before_action :set_playlist, only: %i[show update destroy] def index @playlists = Playlist.all @@ -19,6 +19,11 @@ module API head :no_content end + def destroy + @playlist.destroy + head :no_content + end + private diff --git a/config/routes.rb b/config/routes.rb index f1fd448..867720b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ Rails.application.routes.draw do namespace :api do get '/ping', to: 'application#ping' match '*all', to: 'application#cor_preflight', via: :options - resources :playlists, only: %i[index show create update] + resources :playlists, only: %i[index show create update destroy] resources :sessions, only: :create resources :sounds, only: :show resources :tracks, only: %i[index show] diff --git a/spec/integration/api/playlists_spec.rb b/spec/integration/api/playlists_spec.rb index a4a1166..5dcb36f 100644 --- a/spec/integration/api/playlists_spec.rb +++ b/spec/integration/api/playlists_spec.rb @@ -44,4 +44,11 @@ describe 'API playlists' do name: 'new name' ) end + + it 'destroys a playlist' do + playlist = create :playlist + expect { delete api_playlist_path(playlist), format: :json } + .to change { get api_playlist_path playlist, format: :json } + .from(200).to 404 + end end