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