ActionController :: RoutingError:没有路由匹配[DELETE]“/ logout”

时间:2015-01-30 16:00:25

标签: ruby-on-rails-4

我目前正在关注Michael Hartl的RoR教程和第8章:登录,注销>代码清单8.28。

https://www.railstutorial.org/book/log_in_log_out

测试/集成/ users_login_test.rb

require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

  def setup
    @user = users(:aniket)
  end

  test "login with valid information" do
    get login_path
    post login_path, session: { email: @user.email, password: 'password' }
    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)
  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)错误: UsersLoginTest#test_login_with_valid_information_followed_by_logout: ActionController :: RoutingError:没有路由匹配[DELETE]&#34; / logout&#34;     test / integration / users_login_test.rb:40:在`block in&#39; 21次运行,53次断言,0次失败,1次错误,0次跳过

我似乎无法理解我哪里出错了。请帮忙

0 个答案:

没有答案