From d03007c99fd1bfbbd7f1fa88642b0c8c893fa68e Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 3 May 2015 23:20:43 +0000 Subject: [PATCH] Implement API playlists/update --- app/controllers/api/playlists_controller.rb | 7 ++++++- config/routes.rb | 2 +- spec/integration/api/playlists_spec.rb | 13 ++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/playlists_controller.rb b/app/controllers/api/playlists_controller.rb index 806a706..23e08af 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: :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 diff --git a/config/routes.rb b/config/routes.rb index 5dc225b..f1fd448 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] + resources :playlists, only: %i[index show create update] 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 d6a7baa..a4a1166 100644 --- a/spec/integration/api/playlists_spec.rb +++ b/spec/integration/api/playlists_spec.rb @@ -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