I want to *test destroying a user* through the controller, therefore I do 
in user users_controller_spec.rb:

    it "destroys the requested user" do
      user = User.create! valid_attributes
      expect {
        delete :destroy, {:id => user.to_param}, valid_session
      }.to change(User, :count).by(-1)
    end


The *valid_session* is generated that way

  def valid_session
    controller.stub(current_user: mock_model(User))
  end


In *other models *this* test setup works* fine. But in the user context, I 
get the following *error:*

  1) UsersController DELETE destroy destroys the requested user
     Failure/Error: expect {
       count *should* have been *changed by -1*, but was *changed by 0*

I assume, this is behaviour is related to *valid_session*, which interacts 
with the test, because of creating a second user? So there is one 
additional user added and one destroyed, which equals to zero!

But I don't see a way to avoid this!

The destroy implementation is straight foward:

  def destroy
    @user = User.find(params[:id])

    if @user.destroy
      session[:user_id] = nil
      redirect_to root_url, notice: 'User was successfully deleted and signed 
out!'
  end


Any ideas, 
thanks Harm-?

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/07f7be33-6409-4b7e-86d0-d150acf3a23f%40googlegroups.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to