我有以下路线:
GET /confirm/:token(.:format) Confirmations#confirm控制器:
class ConfirmationsController < ApplicationController
# GET /confirm/<token>
def confirm
@user = User.find_by_email_token(params[:token])
if @user
@user.confirmed = true
@user.email_token = nil
@user.save!
sign_in @user
redirect_to root_url, flash: { success: "Welcome <#{@user.email}>, your address has been verified." }
elsif
redirect_to root_url, flash: { error: "Error: could not find matching user record." }
end
end
end这个简单的confirmations_controller_spec.rb
require 'spec_helper'
describe ConfirmationsController do
let(:user) { FactoryGirl.create(:user, email_token: "some_token") }
describe "Get confirm" do
it "confirms user with valid email_token" do
get :confirm, token: "some_token"
assigns(:user).should eq(user)
user.reload.email_token.should be_nil
end
it "does not confirm user with invalid email_token"
end
end但它失败了:
1) ConfirmationsController Get confirm confirms user with valid email_token
Failure/Error: get :confirm, token: "some_token"
ActionController::RoutingError:
No route matches {:token=>"some_token", :controller=>"confirmations", :action=>"confirm"}
# ./spec/controllers/confirmations_controller_spec.rb:9:in `block (3 levels) in <top (required)>'有没有人看到我搞砸了什么(可能是多件事)?
顺便说一句,我在这里使用了get请求(与put相反),因为它是从基于文本的电子邮件发起的,所以据我所知,我们不能使用put请求……
发布于 2013-01-15 22:14:26
在您的rake路径中,Confirmations不应该有大写字母。
您可以在config/routes.rb中这样定义路由吗
match '/confirm/:token' => 'confirmations#confirm'https://stackoverflow.com/questions/14327185
复制相似问题