7stud -- wrote in post #1014079:
> Uggh.  There must be a hole in my tests:
>
>   def get_user_from_cookie
>     @current_user || begin
>       cookie_array = cookies.signed[:remember_token]
>
>       if cookie_array
>         @current_user = User.authenticate_with_salt(*cookie_arr)
>         return @current_user
>       else
>         return nil
>       end
>
>     end # || block
>   end
>
> *cookie_arr should be *cookie_array.  But my tests didn't throw an
> error.

It turns my get_user_from_cookie method created a branch of code not
present in the book's code.  Namely, in the book when @current_user is
nil, then the right side of the || executes, and when that happens
User.authenticate_with_salt gets called no matter what the cookke_array
is equal to.

In my code, User.authenticate_with_salt doesn't get called
if the cookie_array equals nil, and that creates a blind spot that the
tests don't see.

To mimic the book's code, I changed my method to this:


 def get_user_from_cookie

    @current_user || begin
      cookie_array = cookies.signed[:remember_token] || [nil, nil]
      @current_user = User.authenticate_with_salt(*cookie_arr)  # a user 
or nil
    end

  end

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to