Implements playlists/index action in JSON API

This commit is contained in:
Thibault Jouan 2012-02-26 11:33:43 +00:00
parent 5145717a3c
commit 88d3242843
3 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,8 @@
class Api::V0::PlaylistsController < ApplicationController
respond_to :json
def index
@playlists = Playlist.all
respond_with @playlists
end
end

View File

@ -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]

View File

@ -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