This was posted a while ago, I know, but you should look at the update action in your password_resets controller and make sure that it isn't redirecting to the index.
Regarding my above modifications, I needed "if password.present?" in the encrypt_password expression, otherwise it will end up encrypting an empty string when you save the user. You could also do this in a before_create callback or similar so it doesn't have to run on every single save.
Also, the find_by_email and authenticate methods need to be separated out. I changed it to:
...
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
...
Which I don't really like since I find relying on short circuit evaluation to be iffy.
I have a few small simplifications that I'll share. I'm new to Rails (but not programming in general) so I apologize if anything is bad practice.
ruby
# In the User model. This is now an instance method.defauthenticate(password)
selfifPassword.new(password_hash) == password
enddefencrypt_passwordself.password_hash = Password.create(password)
end
ruby
# In the users controller. defcreate
user = User.find_by_email(params[:email]).authenticate(params[:password])
...etc...
end
respond_with is so sweet. It's odd that the generators with rails 3 still generate respond_to dos.
Okay, this is specifically for controller tests. Add this line to your authenticated tests:
I spent a long time messing with posting the sessions create action, stubs, etc, but finally realized it all just comes down to a cookie.
I am also having a lot of trouble testing this (I am using rspec). I've been working all day on it, and if I figure it out I'll post it.
This was posted a while ago, I know, but you should look at the update action in your password_resets controller and make sure that it isn't redirecting to the index.
According to the FactoryGirl documentation a lot of the syntax in this episode is outdated. Here is some of it rewritten following this.
Regarding my above modifications, I needed "if password.present?" in the encrypt_password expression, otherwise it will end up encrypting an empty string when you save the user. You could also do this in a before_create callback or similar so it doesn't have to run on every single save.
Also, the find_by_email and authenticate methods need to be separated out. I changed it to:
Which I don't really like since I find relying on short circuit evaluation to be iffy.
I forgot to add that with the above changes, you can remove the "password_salt" column.
I have a few small simplifications that I'll share. I'm new to Rails (but not programming in general) so I apologize if anything is bad practice.
Maxsy and airyym,
Regarding the "uninitialized constant User::BCrypt" problem, you need to run "bundle install" in the terminal and then restart the rails server.