From 88d3242843aaefec1e9c50e7a7926dfa0ae205c0 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 26 Feb 2012 11:33:43 +0000 Subject: [PATCH] Implements playlists/index action in JSON API --- .../api/v0/playlists_controller.rb | 8 ++++++ config/routes.rb | 6 +++++ spec/controllers/api/v0/playlists_spec.rb | 27 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 app/controllers/api/v0/playlists_controller.rb create mode 100644 spec/controllers/api/v0/playlists_spec.rb diff --git a/app/controllers/api/v0/playlists_controller.rb b/app/controllers/api/v0/playlists_controller.rb new file mode 100644 index 0000000..c755a70 --- /dev/null +++ b/app/controllers/api/v0/playlists_controller.rb @@ -0,0 +1,8 @@ +class Api::V0::PlaylistsController < ApplicationController + respond_to :json + + def index + @playlists = Playlist.all + respond_with @playlists + end +end diff --git a/config/routes.rb b/config/routes.rb index 4ec0381..ae46c5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,10 @@ Scube::Application.routes.draw do + namespace :api do + namespace :v0 do + resources :playlists, :only => [:index] + end + end + resources :sounds, :only => [:show] resources :users, :only => [:new, :create] diff --git a/spec/controllers/api/v0/playlists_spec.rb b/spec/controllers/api/v0/playlists_spec.rb new file mode 100644 index 0000000..9468dd1 --- /dev/null +++ b/spec/controllers/api/v0/playlists_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe Api::V0::PlaylistsController do + before do + controller.current_user = Factory.create(:user) + end + + describe 'GET index' do + before do + playlist_1 = Factory.create(:playlist, :name => 'Playlist 1') + playlist_2 = Factory.create(:playlist, :name => 'Playlist 2') + end + + def do_get + get :index, :format => :json + JSON.parse(response.body) + end + + it 'lists all playlists' do + do_get.should have(2).items + end + + it 'lists playlists with their name' do + do_get.each { |t| t.keys.should include 'name' } + end + end +end