Implement API playlists/update
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module API
|
||||
class PlaylistsController < ApplicationController
|
||||
before_action :set_playlist, only: :show
|
||||
before_action :set_playlist, only: %i[show update]
|
||||
|
||||
def index
|
||||
@playlists = Playlist.all
|
||||
@@ -14,6 +14,11 @@ module API
|
||||
@playlist.save
|
||||
end
|
||||
|
||||
def update
|
||||
@playlist.update playlist_params
|
||||
head :no_content
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
@@ -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]
|
||||
resources :playlists, only: %i[index show create update]
|
||||
resources :sessions, only: :create
|
||||
resources :sounds, only: :show
|
||||
resources :tracks, only: %i[index show]
|
||||
|
@@ -23,7 +23,7 @@ describe 'API playlists' do
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates playlist' do
|
||||
it 'creates a playlist' do
|
||||
playlist = attributes_for :playlist
|
||||
post api_playlists_path, format: :json, playlist: playlist
|
||||
expect(json).to match(
|
||||
@@ -33,4 +33,15 @@ describe 'API playlists' do
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it 'updates a playlist' do
|
||||
playlist = create :playlist
|
||||
put api_playlist_path(playlist), format: :json, playlist: {
|
||||
name: 'new name'
|
||||
}
|
||||
get api_playlist_path playlist, format: :json
|
||||
expect(json[:playlist]).to include(
|
||||
name: 'new name'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user