私はこのRoRアプリケーションのログインとテストを試みています。私のテストはこれです:Michael HartlのRuby on Railsチュートリアルch 8.3 |なぜこのテストが失敗しているのか分かりません
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_redirected_to root_url
assert_not is_logged_in? # <-- this line is the one that cocks up.
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
ラベル付きの行だけが失敗し、私はなぜそれがわかりません。本自体とまったく同じです。
この関数にログアウトパスルートに削除要求を送信:
def destroy
logout
redirect_to root_url
end
ログアウト機能はこれです:
def logout
session.delete(:user_id)
@current_user = nil
end
とis_logged_in?機能は次のとおりです。
def is_logged_in?
!current_user.nil?
end
これらの3つはすべて、本が本来持っているべきだと言ったとおりのものです。 (私は自分のより良い名前を持っていましたが、私は彼らを絶望から変えました)
サイトはうまく動作しているようです。 Here'sリンクを見れば分かります。私はちょうどいいからログインできます。
私は他の場所でassert_notを使用しましたが、うまくいきました。例:
このテストは成功します。 (「Flash」とは、ページの上部にある小さなボックスのことで、ユーザーにログイン情報が無効であることを通知します)
誰でも知りましたか?どうもありがとう。
私はあなたのやり方を試してみました。多くのveeeeeryありがとう! –
@LlamaTarianism yup問題ない:) –