I’m following Ryan Bates railscasts on password reseting. I decided to implement his code through TDD but one of my tests refuses to work. Whenever I run
context "for checking update succeeds" do
before do
post :update, id: "2012-12-03 04:23:13 UTC"
end
it { should assign_to(:user) }
it { should respond_with(:redirect) }
it { should redirect_to(signin_path) }
it { should set_the_flash.to("Password has been reset.")}
end
I get the following error
Failure/Error: post :update, id: "2012-12-03 04:23:13 UTC"
NoMethodError:
undefined method `<' for nil:NilClass
My controller is as follows
def update
@user = User.find_by_password_reset_token!(params[:id])
if @user.password_reset_sent_at < 2.hours.ago
redirect_to new_password_reset_path, flash[:error] = "Password reset has expired"
elsif @user.update_attributes(params[:user])
redirect_to root_url, flash[:success] = "Password has been reset."
else
render :edit
end
end
I have to assume I’m writing my test wrong in some form or fashion. How do I fix this? Note that I’m aware the utc time is off date and based on yesterday’s time.
Copied from comment:
Seems like
@user.password_reset_sent_atisnil. If it is allowed to benil, you should check byIf it shouldn’t be allowed to, you have a bug somewhere in your model. The test seems fine.