diff --git a/spec/controllers/playlists_controller_spec.rb b/spec/controllers/playlists_controller_spec.rb index 7ab9ef7..cce562e 100644 --- a/spec/controllers/playlists_controller_spec.rb +++ b/spec/controllers/playlists_controller_spec.rb @@ -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 + expect { + post :create, :playlist => Factory.attributes_for(:playlist) + }.to change(Playlist, :count).by(1) + end - it 'creates a new playlist' do - Playlist.should_receive(:new). - with(Factory.attributes_for(:playlist)). - and_return(playlist) - post :create, :playlist => Factory.attributes_for(:playlist) - 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