Implement playlists/create action for API
This commit is contained in:
parent
f8ed140af1
commit
df6d4991f8
@ -4,4 +4,9 @@ class Api::PlaylistsController < Api::ApplicationController
|
|||||||
def index
|
def index
|
||||||
@playlists = Playlist.all
|
@playlists = Playlist.all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@playlist = current_user.playlists.build(params[:playlist].slice(:name))
|
||||||
|
@playlist.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
4
app/views/api/playlists/create.rabl
Normal file
4
app/views/api/playlists/create.rabl
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
object @playlist
|
||||||
|
|
||||||
|
attribute :id
|
||||||
|
attribute :name
|
@ -1,6 +1,6 @@
|
|||||||
Scube::Application.routes.draw do
|
Scube::Application.routes.draw do
|
||||||
namespace :api do
|
namespace :api do
|
||||||
resources :playlists, :only => [:index]
|
resources :playlists, :only => [:index, :create]
|
||||||
resources :sessions, :only => [:create]
|
resources :sessions, :only => [:create]
|
||||||
|
|
||||||
match '*all' => 'application#cor_preflight', :via => :options
|
match '*all' => 'application#cor_preflight', :via => :options
|
||||||
|
@ -30,4 +30,23 @@ describe Api::PlaylistsController do
|
|||||||
do_get.each { |t| t.keys.should include 'name' }
|
do_get.each { |t| t.keys.should include 'name' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'POST create' do
|
||||||
|
def do_create
|
||||||
|
post :create,
|
||||||
|
:format => :json,
|
||||||
|
:playlist => Factory.attributes_for(:playlist)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a new playlist for the current user' do
|
||||||
|
expect {
|
||||||
|
do_create
|
||||||
|
}.to change(controller.current_user.playlists, :count).by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns the playlist' do
|
||||||
|
do_create
|
||||||
|
assigns[:playlist].should be_a Playlist
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
22
spec/integration/api/playlists_spec.rb
Normal file
22
spec/integration/api/playlists_spec.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
feature 'API playlists' do
|
||||||
|
include UserIntegrationHelpers
|
||||||
|
|
||||||
|
background do
|
||||||
|
api_sign_in
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'creates playlist' do
|
||||||
|
playlist = Factory.attributes_for :playlist
|
||||||
|
|
||||||
|
post api_playlists_path,
|
||||||
|
:format => :json,
|
||||||
|
:playlist => playlist
|
||||||
|
|
||||||
|
json = JSON response.body
|
||||||
|
|
||||||
|
json['id'].should be_a Fixnum
|
||||||
|
json['name'].should == playlist[:name]
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user