我正在关注关于密码重置的 Ryan Bates railscasts。我决定通过 TDD 实现他的代码,但我的一个测试拒绝工作。每当我跑步
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
我收到以下错误
Failure/Error: post :update, id: "2012-12-03 04:23:13 UTC"
NoMethodError:
undefined method `<' for nil:NilClass
我的控制器如下
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
我不得不假设我以某种形式或方式写错了我的测试。我该如何解决?请注意,我知道 UTC 时间已过时,并且基于昨天的时间。