我有一个有趣的情况,让我摸不着头脑。我创建了一个控制器(没有模型)来生成密码重置。我已经定义了一个到控制器的 RESTful 路由:
路线.rb
resources :password_resets
我在控制器上创建了一些动作,特别是我的编辑动作:
密码重置控制器.rb
class PasswordResetsController < ApplicationController
# code omitted
def edit
@user = User.find_by_password_reset_token!(params[:id])
end
# code omitted
end
用户可以从我发送给用户的电子邮件中访问编辑:
password_reset.html.haml
%p To reset your password, click the URL below.
= edit_password_reset_url(@user.password_reset_token)
到目前为止一切顺利,我已经设法使用了代码。然后我有测试我的邮件的规范:
describe "password reset" do
let(:user) { FactoryGirl.create(:user) }
let(:mail) { UserMailer.password_reset(user) }
it "sends user password reset url" do
mail.to.should eq([user.email])
end
end
令人惊讶的是,我得到以下信息:
Failure/Error: let(:mail) { UserMailer.password_reset(user) }
ActionView::Template::Error:
No route matches {:action=>"edit", :controller=>"password_resets"}
# ./app/views/user_mailer/password_reset.html.haml:5:in `_app_views_user_mailer_password_reset_html_haml__1760284087840822602_11954840'
# ./app/mailers/user_mailer.rb:7:in `password_reset'
然而,至少通过查看我的路线,路线匹配:
password_resets GET /password_resets(.:format) password_resets#index
POST /password_resets(.:format) password_resets#create
new_password_reset GET /password_resets/new(.:format) password_resets#new
edit_password_reset GET /password_resets/:id/edit(.:format) password_resets#edit
password_reset GET /password_resets/:id(.:format) password_resets#show
PUT /password_resets/:id(.:format) password_resets#update
DELETE /password_resets/:id(.:format) password_resets#destroy
我的测试/路线可能出现什么问题?
非常感谢。