Yeah, I take your point, but I would need to set that up with fixtures,
wouldn't I?
& really I guess I should be seeding the session with a User id & letting
all of the code do its work, not just stubbing the find method on
ActiveRecord.
I'll have a think on it -- for the moment it's quick & uncomplicated, and I
think that current_user returning true is fairly self-explanatory -- maybe
returning :a_logged_in_user would be less evil.
& my attitude there might have more to do with the time here being a
half-hour off of midnight than conscientiousness! ;)
   Doug.

2009/4/27 Zach Dennis <zach.den...@gmail.com>

> On Mon, Apr 27, 2009 at 5:24 PM, doug livesey <biot...@gmail.com> wrote:
> > Refactoring the current_user method a little, then stubbing the find
> method
> > in there did it.
> >
> > # ApplicationController
> > def current_user
> >   User.find( session[:user_id] ) rescue nil
> > end
> >
> > # Scenario step
> > Given /^that a user is logged in to the session$/ do
> >   User.stub!( :find ).and_return( true )
> > end
>
> You probably want to return a User, no? Returning true is entirely
> different than the normal find API w/ActiveRecord. It seems to be
> misleading and I can see where it would cause problems where
> controller or view code that relies on #current_user expects a User,
>
>
> >
> > Cheers,
> >    Doug.
> >
> > 2009/4/27 doug livesey <biot...@gmail.com>
> >>
> >> Except I'm now struggling with how it should work, sorry.
> >> The step for the scenario looks like this:
> >>
> >> Given /^that a user is logged in to the session$/ do
> >>   controller.stub!( :current_user ).and_return( true )
> >> end
> >>
> >> However, when I try to puts the value of current_user as called from the
> >> ApplicationController#authorise method, it returns nil.
> >> I've tried just stubbing out the authorise method, too, but that doesn't
> >> seem to work, either.
> >> Am I approaching this the wrong way?
> >> & cheers again,
> >>    Doug.
> >>
> >> 2009/4/27 doug livesey <biot...@gmail.com>
> >>>
> >>> & that nailed it, cheers man!
> >>>    Doug.
> >>>
> >>> 2009/4/27 doug livesey <biot...@gmail.com>
> >>>>
> >>>> > Please be sure to clip the relevant parts when responding - "all of
> >>>> > that" is only meaningful if I look at the other email in this
> thread.
> >>>> > Easy on my desk top. Not so easy on my phone.
> >>>>
> >>>> Bit too used to gmail threads, sorry!
> >>>>    Doug.
> >>>
> >>
> >
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users@rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>
>
>
> --
> Zach Dennis
> http://www.continuousthinking.com (personal)
> http://www.mutuallyhuman.com (hire me)
> @zachdennis (twitter)
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to