0

http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic/で説明されているように、Authlogicパスワードリセットの動作を検証するためにいくつかのテストを実装しようとしています。

私はAuthlogic、Shoulda、Webrat、Factory Girlを使用していますが、これが私のテストです。

require 'test_helper'

class PasswordResetTest < ActionController::IntegrationTest


  setup :activate_authlogic

  context "A registered user" do
    setup do
      @reggie = Factory(:reggie)

    end

    should "not allow logged in users to change password" do
      visit signin_path
      fill_in 'Email', :with => @reggie.email
      fill_in 'Password', :with => @reggie.password
      click_button 'Sign In'
      assert_equal controller.session['user_credentials'], @reggie.persistence_token
      visit change_password_path
      assert_equal account_path, path
      assert_match /must be logged out/, flash[:notice]
      visit signout_path
      assert_equal controller.session['user_credentials'], nil
      visit change_password_path
      assert_equal change_password_path, path
    end

    should "allow logged out users to change password" do
      visit signout_path
      assert_equal controller.session['user_credentials'], nil
      visit change_password_path
      assert_template :new
      fill_in 'email', :with => @reggie.email
      click_button 'Reset my password'
      assert_match /Please check your email/, flash[:notice]
      assert !ActionMailer::Base.deliveries.empty?
      sent = ActionMailer::Base.deliveries.first
      assert_equal [@reggie.email], sent.to
      assert_match /Password Reset Instructions/, sent.subject
      assert_not_nil @reggie.perishable_token
      #TODO
      p "Perishable Token #{@reggie.perishable_token}"
      assert_match assigns[:edit_password_reset_url], sent.body
    end
  end
end

テストの最後の2行で、送信されたリンクに正しいperishable_tokenが含まれていることを確認しようとしています。これは、印刷された生鮮トークンと送信されたリンクのトークンで常に異なって表示されます。

この動作をどのようにテストする必要がありますか?

ありがとう、Siva

4

2 に答える 2

0

気をつけろ。Authlogic は魔法です。特定の操作によって User オブジェクトが変化し、その場合、perishable_token は消滅します (再生成されます)。

signout_pathあなたの訪問は本当にあなたをログアウトさせているのだろうか. 通常、UserSession が RESTful の場合、リソースに HTTP DELETE を発行して、実際にセッションを削除する必要があります。(GET を使用して) パスにアクセスするだけでは、明示的なルート (へのマッピングなど) がない限り、セッションは削除されませ'/logout':controller => 'user_sessions', :action => 'destroy'

于 2009-10-02T05:01:04.037 に答える
0

の行を次のように変更しnotifier.rbます。

body          :edit_password_resets_url => edit_password_resets_url(user.perishable_token)
于 2010-02-11T01:18:53.110 に答える