3
我有一个相匹配的用户名这样的约束路线:RSpec的测试自定义的用户名路由失败
controller :users, :path => '/:username', :as => :user, :constrain => { :username => /^_?[a-z]_?(?:[a-z0-9]_?)*$/i } do
# lots of nested routes go here
end
当我去写这个RSpec的测试(与使用user_id
正常人一样),所有的测试都因为它“无法找到路线”,即使它在服务器上正常工作也会失败。
describe "for an invalid request" do
it "should render a 404 if an associated photo is not found" do
# give it a bad photo id
xhr :post, :destroy, :id => "999999", :photo_id => "999999", :username => @photo_owner.username
# not found
response.status.should == not_found
end
end
此测试切换到用户名前工作正常,我用我的路线user_id
时:
resources :users do
# nested routes
end
和
xhr :post, :destroy, :id => "999999", :photo_id => "999999", :user_id => @photo_owner.id
那我做错了什么已经改变?
我的服务器控制台显示这意味着我应该在所有正确传递的参数:
Processing by TagsController#destroy as JS
Parameters: {"constrain"=>{"username"=>/^_?[a-z]_?(?:[a-z0-9]_?)*$/i}, "username"=>"rubynewb", "photo_id"=>"2004-the-title-of-the-photo-here", "id"=>"1797"}
谢谢!这样一个简单的错误! – ZeNewb 2012-02-10 16:17:04