Implement API playlists/update
This commit is contained in:
parent
317c2b687f
commit
d03007c99f
@ -1,6 +1,6 @@
|
|||||||
module API
|
module API
|
||||||
class PlaylistsController < ApplicationController
|
class PlaylistsController < ApplicationController
|
||||||
before_action :set_playlist, only: :show
|
before_action :set_playlist, only: %i[show update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@playlists = Playlist.all
|
@playlists = Playlist.all
|
||||||
@ -14,6 +14,11 @@ module API
|
|||||||
@playlist.save
|
@playlist.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@playlist.update playlist_params
|
||||||
|
head :no_content
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ Rails.application.routes.draw do
|
|||||||
namespace :api do
|
namespace :api do
|
||||||
get '/ping', to: 'application#ping'
|
get '/ping', to: 'application#ping'
|
||||||
match '*all', to: 'application#cor_preflight', via: :options
|
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 :sessions, only: :create
|
||||||
resources :sounds, only: :show
|
resources :sounds, only: :show
|
||||||
resources :tracks, only: %i[index show]
|
resources :tracks, only: %i[index show]
|
||||||
|
@ -23,7 +23,7 @@ describe 'API playlists' do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates playlist' do
|
it 'creates a playlist' do
|
||||||
playlist = attributes_for :playlist
|
playlist = attributes_for :playlist
|
||||||
post api_playlists_path, format: :json, playlist: playlist
|
post api_playlists_path, format: :json, playlist: playlist
|
||||||
expect(json).to match(
|
expect(json).to match(
|
||||||
@ -33,4 +33,15 @@ describe 'API playlists' do
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user