Rails:用户注销会产生错误

时间:2015-01-20 17:16:27

标签: ruby-on-rails

我正在浏览www.railstutorial.org/,而且我已经陷入了将用户从应用中删除的问题。

当我退出时,我的终端出现错误:

1) Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
ActionController::RoutingError: uninitialized constant UsessionsController
    test/integration/users_login_test.rb:29:in `block in <class:UsersLog

这是我的test / integration / users_login_test.rb

的代码
require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

    def setup
    @user = users(:michael)
  end

  test "login with invalid information" do
    get login_path
    assert_template 'sessions/new'
    post login_path, session: { email: "", password: "" }
    assert_template 'sessions/new'
    assert_not flash.empty?
    get root_path
    assert flash.empty?
  end

  test "login with valid information followed by logout" do
    get login_path
    post login_path, session: { email: @user.email, password: 'password' }
    assert is_logged_in?
    assert_redirected_to @user
    follow_redirect!
    assert_template 'users/show'
    assert_select "a[href=?]", login_path, count: 0
    assert_select "a[href=?]", logout_path
    assert_select "a[href=?]", user_path(@user)
    delete logout_path
    assert_not is_logged_in?
    assert_redirected_to root_url
    follow_redirect!
    assert_select "a[href=?]", login_path
    assert_select "a[href=?]", logout_path,      count: 0
    assert_select "a[href=?]", user_path(@user), count: 0
  end
end

知道我哪里出错了?

1 个答案:

答案 0 :(得分:1)

从错误中,您可能会遇到拼写错误:UsessionsController,因为您正在测试登录功能,您可能希望在控制器定义中定义SessionsController

纠正控制器应解决问题。