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