【问题标题】:Authlogic edit_password_reset_url in Functional / Integration Tests功能/集成测试中的 Authlogic edit_password_reset_url
【发布时间】:2009-08-18 00:07:02
【问题描述】:

我正在尝试实施一些测试来验证 Authlogic 密码重置的行为,如 http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic/ 中所述

我正在使用 Authlogic、Shouda、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,并且打印的 Perishable Token 和发出的链接中的令牌总是不同。

我应该如何测试这种行为?

谢谢,湿婆

【问题讨论】:

    标签: authlogic functional-testing


    【解决方案1】:

    小心。 Authlogic 很神奇。某些操作会导致 User 对象发生变异,当它发生变异时,perishable_token 井会消失(重新生成)。

    我想知道您的访问 signout_path 是否真的让您退出。通常,如果您的 UserSession 是 RESTful 的,您必须向资源发出 HTTP DELETE 才能实际删除会话。除非您有明确的路线(例如,'/logout':controller =&gt; 'user_sessions', :action =&gt; 'destroy' 的映射),否则仅访问路径(使用 GET)不会删除会话

    【讨论】:

      【解决方案2】:

      notifier.rb 中的行改为:

      body          :edit_password_resets_url => edit_password_resets_url(user.perishable_token)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-06
        • 1970-01-01
        • 2021-04-06
        • 1970-01-01
        相关资源
        最近更新 更多