问题测试 Rails 帖子
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,问题出在参数值上
看来是有什么问题了。 (点)在参数值中。
如果我更改为不带“.”的其他值(点),一切都很好。以下内容按预期工作:
So, the problem was in the parameter value for
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: