Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Rails Layouts and CSS Frameworks Remember Me Setting a Signed Token

Not sure what's making this test not pass (remember_me_token)

Hey all!

I'm having trouble getting a test to pass even though I believe it's coded exactly as shown in the video.

Here's the test

 it "sets the remember_me_token cookie if chosen" do
        expect(cookies).to_not have_key('remember_me_token')
        post :create, email: "jason@treehouse.com", password: "treehouse1", remember_me: "1"
        expect(cookies).to have_key('remember_me_token')
        expect(cookies['remember_me_token']).to_not be_nil
      end
    end
def create
    user = User.find_by(email: params[:email])
    if user && user.authenticate(params[:password])
     if params[:remember_me]
      signed_token = Rails.application.message_verifier(:remember_me).generate(user.id)
      cookies.permanent.signed[:remember_me_token] = signed_token
    end
      session[:user_id] = user.id
      flash[:success] = "Thanks for logging in!"
      redirect_to todo_lists_path
    else
      flash[:error] = "There was a problem logging in. Please check your email and password."
      render action: 'new'
    end
  end

And here's the error I'm getting:

error

The entire project is over on github too, if that would help.

Any ideas?

Thanks in advance for the help! :grinning:

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

The problem is in your spec. Line 50:

post :create, email: "jason@treehouse.com", password: "treehouse1", remember_me: "1"

This email is not the same as the email of the user created at the beginning of this series of tests, line 19:

let!(:user) { User.create(first_name: "Jason", last_name: "Seifer", email: "jason@teamtreehouse.com", password: "treehouse1"

So just add team in line 50 and it should work properly :)

AUGH!

Nice catch.

Grumble grumble....