Fix playlist/update action behaviour with invalid params
This commit is contained in:
parent
7b2b594d7d
commit
c023a071d0
@ -22,7 +22,10 @@ class PlaylistsController < ApplicationController
|
||||
|
||||
def update
|
||||
@playlist = Playlist.find(params[:id])
|
||||
@playlist.update_attributes params[:playlist]
|
||||
if @playlist.update_attributes params[:playlist]
|
||||
redirect_to :action => 'index'
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -58,24 +58,36 @@ describe PlaylistsController do
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
it 'updates the playlist' do
|
||||
playlist = Factory.create(:playlist)
|
||||
Playlist.any_instance.should_receive(:update_attributes).
|
||||
with({'name' => 'Rock'})
|
||||
put :update, :id => playlist.id.to_s, :playlist => {:name => 'Rock'}
|
||||
let (:playlist) { Factory.create(:playlist) }
|
||||
|
||||
def do_update
|
||||
put :update, :id => playlist.id.to_s, :playlist => { :name => 'Rock' }
|
||||
end
|
||||
|
||||
context 'whith valid params' do
|
||||
it 'updates the playlist' do
|
||||
Playlist.any_instance.should_receive(:update_attributes).
|
||||
with({'name' => 'Rock'})
|
||||
do_update
|
||||
end
|
||||
|
||||
it 'redirects to the playlists index' do
|
||||
do_update
|
||||
response.should redirect_to(:action => 'index')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid params' do
|
||||
before { Playlist.any_instance.stub(:save).and_return(false) }
|
||||
|
||||
it 'assigns the requested playlist as @playlist' do
|
||||
playlist = Factory.create(:playlist)
|
||||
put :update, :id => playlist.id.to_s, :playlist => {:name => 'Rock'}
|
||||
do_update
|
||||
assigns[:playlist].should == playlist
|
||||
end
|
||||
|
||||
context 'when the playlist updates successfully' do
|
||||
it 'redirects to the playlists index' do
|
||||
playlist = Factory.create(:playlist)
|
||||
put :update, :id => playlist.id.to_s, :playlist => Factory.attributes_for(:playlist)
|
||||
response.should redirect_to(:action => 'index')
|
||||
it 'renders the edit template' do
|
||||
do_update
|
||||
response.should render_template('edit')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user