Improve PlaylistsController POST create specs
This commit is contained in:
parent
6c6ed3b0b2
commit
7b2b594d7d
@ -29,36 +29,25 @@ describe PlaylistsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST create' do
|
describe 'POST create' do
|
||||||
let(:playlist) { mock_model(Playlist).as_null_object }
|
context 'whith valid params' do
|
||||||
before { Playlist.stub(:new).and_return(playlist) }
|
|
||||||
|
|
||||||
it 'creates a new playlist' do
|
it 'creates a new playlist' do
|
||||||
Playlist.should_receive(:new).
|
expect {
|
||||||
with(Factory.attributes_for(:playlist)).
|
|
||||||
and_return(playlist)
|
|
||||||
post :create, :playlist => Factory.attributes_for(:playlist)
|
post :create, :playlist => Factory.attributes_for(:playlist)
|
||||||
|
}.to change(Playlist, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'saves the playlist' do
|
|
||||||
playlist.should_receive(:save)
|
|
||||||
post :create, :playlist => {}
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the playlist saves successfully' do
|
|
||||||
it 'redirects to the playlists index' do
|
it 'redirects to the playlists index' do
|
||||||
post :create, :playlist => {}
|
post :create, :playlist => Factory.attributes_for(:playlist)
|
||||||
response.should redirect_to(:action => 'index')
|
response.should redirect_to(:action => 'index')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the playlist fails to save' do
|
context 'whith invalid params' do
|
||||||
before do
|
before { Playlist.any_instance.stub(:save).and_return(false) }
|
||||||
playlist.stub(:save).and_return(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'assigns the playlist as @playlist' do
|
it 'assigns the playlist as @playlist' do
|
||||||
post :create, :playlist => {}
|
post :create, :playlist => {}
|
||||||
assigns[:playlist].should eq(playlist)
|
assigns[:playlist].should be_a_new(Playlist)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders the new template' do
|
it 'renders the new template' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user