问题测试 Rails 帖子

发布于 2024-10-16 09:07:16 字数 813 浏览 5 评论 0原文

使用 Rails 3.0.3。

我在routes.rb中有以下路线:


 match "user/create_new_password/:reset_password_key" =>"users#create_new_password", :via=>[:get, :post], :as=>:create_new_password

当在视图中使用此路线时,通过表单,它可以正常工作,但是我无法测试它。我在功能测试中这样做:


test "fail create password with invalid key" do
   post :create_new_password, {:create_new_password=>{:password=>"1", :password_confirmation=>"1"}, :reset_password_key=>"user.reset_password_key"} 
end

我收到错误:


ActionController::RoutingError: No route matches {:create_new_password=>{:password=>"1", :password_confirmation=>"1"}, :reset_password_key=>"user.reset_password_key", :controller=>"users", :action=>"create_new_password"}

这里出了什么问题?

Using Rails 3.0.3.

I have the following route in routes.rb:


 match "user/create_new_password/:reset_password_key" =>"users#create_new_password", :via=>[:get, :post], :as=>:create_new_password

When using this route in the view, with a form, it works ok, however I'm not able to test it. I'm doing this in my functional test:


test "fail create password with invalid key" do
   post :create_new_password, {:create_new_password=>{:password=>"1", :password_confirmation=>"1"}, :reset_password_key=>"user.reset_password_key"} 
end

And I'm getting the error:


ActionController::RoutingError: No route matches {:create_new_password=>{:password=>"1", :password_confirmation=>"1"}, :reset_password_key=>"user.reset_password_key", :controller=>"users", :action=>"create_new_password"}

What's wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南薇 2024-10-23 09:07:16

所以,问题出在参数值上

:reset_password_key


test "fail create password with invalid key" do
   post :create_new_password, {:create_new_password=>{:password=>"1", :password_confirmation=>"1"}, :reset_password_key=>"user.reset_password_key"} 
end

看来是有什么问题了。 (点)在参数值中。

如果我更改为不带“.”的其他值(点),一切都很好。以下内容按预期工作:


test "fail create password with invalid key" do
   post :create_new_password, {:create_new_password=>{:password=>"1", :password_confirmation=>"1"}, :reset_password_key=>"user_reset_password_key"} 
end

So, the problem was in the parameter value for

:reset_password_key


test "fail create password with invalid key" do
   post :create_new_password, {:create_new_password=>{:password=>"1", :password_confirmation=>"1"}, :reset_password_key=>"user.reset_password_key"} 
end

It seems that it's something wrong with the . (dot) in the parameter value.

If I change to other value without the "." (dot), everything is fine. The following works as expected:


test "fail create password with invalid key" do
   post :create_new_password, {:create_new_password=>{:password=>"1", :password_confirmation=>"1"}, :reset_password_key=>"user_reset_password_key"} 
end

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文