On Sun, 3 Jan 2016, at 01:58 PM, Brandon Burton wrote:
> 
> For the session user id, would that look something like 
> 'expect(session[:user_id]).to eq(user_id)'? 

No – that would be a way to write an assertion to check that the session’s 
user_id key contains the contents of a (local) user_id variable, but you’ve no 
need to do that.

What I was suggesting was that your `sign_in` method (in your spec’s 
authentication helper) could look like this:

    def sign_in(user)
      session[:user_id] = user.id
    end

I came up with that because I looked at how your `current_user` method is 
implemented, and that just calls `User#find_by_id`, passing in the value of 
`session[:user_id]`.

You can assign things to `session` because Rails makes the session available to 
you in a controller test.

It’s better than stubbing out `current_user` because it executes your real 
code, saving plenty of confusion when people are trying to debug your code.

-- 
You received this message because you are subscribed to the Google Groups 
"North West Ruby User Group (NWRUG)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send an email to [email protected].
Visit this group at https://groups.google.com/group/nwrug-members.
For more options, visit https://groups.google.com/d/optout.

Reply via email to