首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Rails测试:自定义路由的“无路由匹配”

Rails测试:自定义路由的“无路由匹配”
EN

Stack Overflow用户
提问于 2013-01-15 05:37:45
回答 1查看 1.6K关注 0票数 0

我有以下路线:

代码语言:javascript
复制
GET    /confirm/:token(.:format)  Confirmations#confirm

控制器:

代码语言:javascript
复制
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

代码语言:javascript
复制
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

但它失败了:

代码语言:javascript
复制
  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请求……

EN

Stack Overflow用户

回答已采纳

发布于 2013-01-15 22:14:26

在您的rake路径中,Confirmations不应该有大写字母。

您可以在config/routes.rb中这样定义路由吗

代码语言:javascript
复制
match '/confirm/:token' => 'confirmations#confirm'
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14327185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档