我有以下路线:
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
请求...