From b3cfa88bb9e009e6fb8431a3a2a4e348d898a21c Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Fri, 1 May 2015 20:06:20 +0000 Subject: [PATCH] Implement playlists/show in API --- app/controllers/api/playlists_controller.rb | 4 ++++ app/views/api/playlists/show.rabl | 4 ++++ config/routes.rb | 2 +- spec/integration/api/playlists_spec.rb | 10 ++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 app/views/api/playlists/show.rabl diff --git a/app/controllers/api/playlists_controller.rb b/app/controllers/api/playlists_controller.rb index b3a576a..4466bad 100644 --- a/app/controllers/api/playlists_controller.rb +++ b/app/controllers/api/playlists_controller.rb @@ -4,6 +4,10 @@ module API @playlists = Playlist.all end + def show + @playlist = Playlist.find(params[:id]) + end + def create @playlist = current_user.playlists.build playlist_params @playlist.save diff --git a/app/views/api/playlists/show.rabl b/app/views/api/playlists/show.rabl new file mode 100644 index 0000000..002dfce --- /dev/null +++ b/app/views/api/playlists/show.rabl @@ -0,0 +1,4 @@ +object @playlist + +attribute :id +attribute :name diff --git a/config/routes.rb b/config/routes.rb index 7e3922a..dd5ae1a 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 create] + resources :playlists, only: %i[index show create] resources :sessions, only: :create resources :sounds, only: :show resources :tracks, only: :index diff --git a/spec/integration/api/playlists_spec.rb b/spec/integration/api/playlists_spec.rb index 9ef4ede..4251281 100644 --- a/spec/integration/api/playlists_spec.rb +++ b/spec/integration/api/playlists_spec.rb @@ -15,6 +15,16 @@ describe 'API playlists' do ] end + it 'shows a playlist' do + playlist = create :playlist + get api_playlist_path playlist, format: :json + + expect(json).to match( + id: playlist.id, + name: playlist.name + ) + end + it 'creates playlist' do playlist = attributes_for :playlist post api_playlists_path,