diff --git a/app/controllers/api/playlists_controller.rb b/app/controllers/api/playlists_controller.rb index c6e31a7..fc4e367 100644 --- a/app/controllers/api/playlists_controller.rb +++ b/app/controllers/api/playlists_controller.rb @@ -11,8 +11,11 @@ module API def create @playlist = current_user.playlists.build playlist_params - @playlist.save - render :show, status: :created + if @playlist.save + render :show, status: :created + else + render json: :nothing, status: :unprocessable_entity + end end def update diff --git a/spec/integration/api/playlists_spec.rb b/spec/integration/api/playlists_spec.rb index 82c2320..65d1914 100644 --- a/spec/integration/api/playlists_spec.rb +++ b/spec/integration/api/playlists_spec.rb @@ -40,6 +40,14 @@ describe 'API playlists' do } ) end + + context 'when playlist is invalid' do + let(:playlist) { attributes_for :playlist, name: '' } + + it 'responds with unprocessable entity status' do + expect(response).to have_http_status 422 + end + end end it 'updates a playlist' do