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