\"users#create_new_password\", :via=>[:get, :post], :as=>:crea" />
开发者

Question testing rails post

开发者 https://www.devze.com 2023-02-09 06:59 出处:网络
Using Rails 3.0.3. I ha开发者_如何学编程ve the following route in routes.rb: match \"user/create_new_password/:reset_password_key\" =>\"users#create_new_password\", :via=>[:get, :post], :as=>:crea

Using Rails 3.0.3.

I ha开发者_如何学编程ve 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号