From 6944fe557c695923b988db775978ad8444e5c5bb Mon Sep 17 00:00:00 2001 From: binarylogic Date: Mon, 23 Mar 2009 02:25:18 -0400 Subject: [PATCH] Release v2.0 --- lib/authlogic/acts_as_authentic/base.rb | 13 ++++++++++--- lib/authlogic/acts_as_authentic/password.rb | 1 + .../acts_as_authentic/single_access_token.rb | 2 ++ test/session_test/session_test.rb | 9 +++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/authlogic/acts_as_authentic/base.rb b/lib/authlogic/acts_as_authentic/base.rb index e73ba457..de93ba50 100644 --- a/lib/authlogic/acts_as_authentic/base.rb +++ b/lib/authlogic/acts_as_authentic/base.rb @@ -1,6 +1,6 @@ module Authlogic module ActsAsAuthentic - # Adds in the acts_as_authentic method to ActiveRecord. + # Provides the base functionality for acts_as_authentic module Base def self.included(klass) klass.class_eval do @@ -27,14 +27,21 @@ def acts_as_authentic(&block) yield self if block_given? acts_as_authentic_modules.each { |mod| include mod } end - + + # Since this part of Authlogic deals with another class, ActiveRecord, we can't just start including things + # in ActiveRecord itself. A lot of these module includes need to be triggered by the acts_as_authentic method + # call. For example, you don't want to start adding in email validations and what not into a model that has + # nothing to do with Authlogic. + # + # That being said, this is your tool for extending Authlogic and "hooking" into the acts_as_authentic call. def add_acts_as_authentic_module(mod) modules = acts_as_authentic_modules modules << mod modules.uniq! write_inheritable_attribute(:acts_as_authentic_modules, modules) end - + + # This is the same as add_acts_as_authentic_module, except that it removes the module from the list. def remove_acts_as_authentic_module(mod) acts_as_authentic_modules.delete(mod) acts_as_authentic_modules diff --git a/lib/authlogic/acts_as_authentic/password.rb b/lib/authlogic/acts_as_authentic/password.rb index f6ab5f0b..2312bdc3 100644 --- a/lib/authlogic/acts_as_authentic/password.rb +++ b/lib/authlogic/acts_as_authentic/password.rb @@ -11,6 +11,7 @@ def self.included(klass) end end + # All configuration for the password aspect of acts_as_authentic. module Config # The name of the crypted_password field in the database. # diff --git a/lib/authlogic/acts_as_authentic/single_access_token.rb b/lib/authlogic/acts_as_authentic/single_access_token.rb index 83547310..3bd552e4 100644 --- a/lib/authlogic/acts_as_authentic/single_access_token.rb +++ b/lib/authlogic/acts_as_authentic/single_access_token.rb @@ -10,6 +10,7 @@ def self.included(klass) end end + # All configuration for the single_access token aspect of acts_as_authentic. module Config def change_single_access_token_with_password(value = nil) config(:change_single_access_token_with_password, value, false) @@ -17,6 +18,7 @@ def change_single_access_token_with_password(value = nil) alias_method :change_single_access_token_with_password=, :change_single_access_token_with_password end + # All method, for the single_access token aspect of acts_as_authentic. module Methods def self.included(klass) return if !klass.column_names.include?("single_access_token") diff --git a/test/session_test/session_test.rb b/test/session_test/session_test.rb index e1c50ec1..af47bfbf 100644 --- a/test/session_test/session_test.rb +++ b/test/session_test/session_test.rb @@ -20,6 +20,15 @@ def test_persist_persist_by_session assert_equal ben, session.record assert_equal ben.persistence_token, @controller.session["user_credentials"] end + + def test_persist_persist_by_session_with_token_only + ben = users(:ben) + set_session_for(ben) + @controller.session["user_credentials_id"] = nil + assert session = UserSession.find + assert_equal ben, session.record + assert_equal ben.persistence_token, @controller.session["user_credentials"] + end def test_after_save_update_session ben = users(:ben)