Skip to content

Commit

Permalink
Release v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Mar 23, 2009
1 parent 78f5bef commit 6944fe5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/authlogic/acts_as_authentic/base.rb
@@ -1,6 +1,6 @@
module Authlogic module Authlogic
module ActsAsAuthentic module ActsAsAuthentic
# Adds in the acts_as_authentic method to ActiveRecord. # Provides the base functionality for acts_as_authentic
module Base module Base
def self.included(klass) def self.included(klass)
klass.class_eval do klass.class_eval do
Expand All @@ -27,14 +27,21 @@ def acts_as_authentic(&block)
yield self if block_given? yield self if block_given?
acts_as_authentic_modules.each { |mod| include mod } acts_as_authentic_modules.each { |mod| include mod }
end 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) def add_acts_as_authentic_module(mod)
modules = acts_as_authentic_modules modules = acts_as_authentic_modules
modules << mod modules << mod
modules.uniq! modules.uniq!
write_inheritable_attribute(:acts_as_authentic_modules, modules) write_inheritable_attribute(:acts_as_authentic_modules, modules)
end 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) def remove_acts_as_authentic_module(mod)
acts_as_authentic_modules.delete(mod) acts_as_authentic_modules.delete(mod)
acts_as_authentic_modules acts_as_authentic_modules
Expand Down
1 change: 1 addition & 0 deletions lib/authlogic/acts_as_authentic/password.rb
Expand Up @@ -11,6 +11,7 @@ def self.included(klass)
end end
end end


# All configuration for the password aspect of acts_as_authentic.
module Config module Config
# The name of the crypted_password field in the database. # The name of the crypted_password field in the database.
# #
Expand Down
2 changes: 2 additions & 0 deletions lib/authlogic/acts_as_authentic/single_access_token.rb
Expand Up @@ -10,13 +10,15 @@ def self.included(klass)
end end
end end


# All configuration for the single_access token aspect of acts_as_authentic.
module Config module Config
def change_single_access_token_with_password(value = nil) def change_single_access_token_with_password(value = nil)
config(:change_single_access_token_with_password, value, false) config(:change_single_access_token_with_password, value, false)
end end
alias_method :change_single_access_token_with_password=, :change_single_access_token_with_password alias_method :change_single_access_token_with_password=, :change_single_access_token_with_password
end end


# All method, for the single_access token aspect of acts_as_authentic.
module Methods module Methods
def self.included(klass) def self.included(klass)
return if !klass.column_names.include?("single_access_token") return if !klass.column_names.include?("single_access_token")
Expand Down
9 changes: 9 additions & 0 deletions test/session_test/session_test.rb
Expand Up @@ -20,6 +20,15 @@ def test_persist_persist_by_session
assert_equal ben, session.record assert_equal ben, session.record
assert_equal ben.persistence_token, @controller.session["user_credentials"] assert_equal ben.persistence_token, @controller.session["user_credentials"]
end 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 def test_after_save_update_session
ben = users(:ben) ben = users(:ben)
Expand Down

0 comments on commit 6944fe5

Please sign in to comment.