パスワードのリセットに関する Ryan Bates の railscasts をフォローしています。彼のコードを TDD で実装することにしましたが、私のテストの 1 つが機能しません。私が走るたびに
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 時刻は日付がずれており、昨日の時刻に基づいていることに注意してください。