Handle save error in API playlists/update
This commit is contained in:
parent
5f993e4bd3
commit
223a6e7a85
@ -19,8 +19,11 @@ module API
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@playlist.update playlist_params
|
if @playlist.update playlist_params
|
||||||
head :no_content
|
head :no_content
|
||||||
|
else
|
||||||
|
render json: @playlist.errors, status: :unprocessable_entity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -56,15 +56,40 @@ describe 'API playlists' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates a playlist' do
|
describe 'playlist update' do
|
||||||
playlist = create :playlist
|
let(:name) { 'new name' }
|
||||||
put api_playlist_path(playlist), format: :json, playlist: {
|
let(:playlist) { create :playlist }
|
||||||
name: 'new name'
|
|
||||||
}
|
before do
|
||||||
get api_playlist_path playlist, format: :json
|
put api_playlist_path(playlist), format: :json, playlist: {
|
||||||
expect(json[:playlist]).to include(
|
name: name
|
||||||
name: 'new name'
|
}
|
||||||
)
|
end
|
||||||
|
|
||||||
|
it 'responds with no content status' do
|
||||||
|
expect(response).to have_http_status 204
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'updates the playlist' do
|
||||||
|
get api_playlist_path playlist, format: :json
|
||||||
|
expect(json[:playlist]).to include(
|
||||||
|
name: 'new name'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when playlist is invalid' do
|
||||||
|
let(:name) { '' }
|
||||||
|
|
||||||
|
it 'responds with unprocessable entity status' do
|
||||||
|
expect(response).to have_http_status 422
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns errors' do
|
||||||
|
expect(json 422).to match(
|
||||||
|
name: [an_instance_of(String)]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'destroys a playlist' do
|
it 'destroys a playlist' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user