[rspec-users] Where is current_user?

David Chelimsky dchelimsky at gmail.com
Mon Oct 20 12:53:47 EDT 2008


On Mon, Oct 20, 2008 at 11:34 AM, Harry Bishop <lists at ruby-forum.com> wrote:
> Zach Dennis wrote:
>
>> The @current_user instance variable was being set by the
>> ApplicationController#retrieve_user method, but your spec was stubbing
>> out the #retrieve_user method. This means that the original
>> ApplicationController#retreieve_user method is not going to get called
>> because you have explicitly told RSpec to stub out that method and
>> return the current user from your spec. Since the original method is
>> not going to get called the @current_user instance variable in the
>> controller never gets set.
>>
> Hi Zack,
> I put the stub in to advance the process to the MotionsController
> because without it the process hangs in ApplicationController with a
> redirect to show.
> My test log shows the 302 but show doesn't get called.  Is there some
> way around that?
>
> So far David's method of making retrieve_user return @current_user

That's not what I recommended. I recommended adding a new method named
current_user that returns @current_user, so you can refer to just
current_user in method calls and stub that out if you want to control
its value from the code example.

> and stubbing the protected method is_showable? works but doesn't
> recognize the inheritance that should be there for @current_user.

Inheritance?

>
> HR
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list