Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you stub a `current_user` with update_attributes set to false?

This is a pure syntactical question. I'm very new to RSpec.

I basically want to write something on the lines of this erroring line :

controller.stub!(:current_user(:update_attributes => false))

Anyone know how to properly write that?

RSpec's default looks like this :

User.stub(:find) { mock_user(:update_attributes => false) }
like image 266
Trip Avatar asked Sep 09 '10 23:09

Trip


1 Answers

This looks like a case for stub_chain:

controller.stub_chain(:current_user,:update_attributes).and_return(false)

Note that this is just going to replace methods in the list in the order they occur, so for this to make sense you'll have a current_user.update_attributes in your controller. If you have something like @user.update_attributes, I don't think it will work.

More info on APIDock

like image 186
zetetic Avatar answered Oct 04 '22 21:10

zetetic