简体   繁体   English

在Rails 4中如何测试设计自定义注册路径?

[英]In Rails 4 How to Test Devise Custom Registration Paths?

I have customized the devise paths like this : 我已经定制了像这样的devise路径:

devise_for :users, path: '', path_names: { sign_in: 'signin', sign_out: 'signout', password: 'secret', confirmation: 'verification', unlock: 'unblock', registration: 'signup', sign_up: 'new' }

So for example it makes the user signup path like this http://localhost:3000/signup/new . 因此,例如,它使用户注册路径像这样http://localhost:3000/signup/new Now the problem is, I don't know how to test this page. 现在的问题是,我不知道如何测试此页面。 Here's the test for users_controller : 这是users_controller的测试:

    require 'test_helper'

    class UsersControllerTest < ActionController::TestCase

      test "should get signup" do
        get :signup_new
        assert_response :success
        assert_select "title", "SignUp | #{Figaro.env.app_name}"
      end

    end

How to visit these custom paths in my test files? 如何在测试文件中访问这些自定义路径?

You are probably testing the wrong controller. 您可能正在测试错误的控制器。 Check your routes ( rake routes ) to see which controller is assigned to handle your Devise authentication routes. 检查您的路由( rake routes )以查看分配了哪个控制器来处理您的Devise身份验证路由。 By default I believe it is Devise::SessionsController . 默认情况下,我相信它是Devise::SessionsController

I do not think this is your intent, but it is worth mentioning that you should not test the devise gem. 我不认为这是你的意图,但值得一提的,你应该测试色器件宝石。

Note that requests for ActionController::TestCase are simulated. 请注意,模拟了对ActionController :: TestCase的请求。 If you want to test true requests then you should look into integration testing. 如果您想测试真实的请求,则应该进行集成测试。 A brief overview can be found here 可以在这里找到简要概述

UPDATE UPDATE

Take a look in the Devise gem for some examples of how to log a user in here . 在Devise gem中查看有关如何在此处登录用户的一些示例。 Notice that include Devise::TestHelpers is added near the top of the test class which adds a sign_in method. 注意,在测试类顶部附近添加了include Devise::TestHelpers ,它添加了sign_in方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM