Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added should_be_authentic shoulda macro

  • Loading branch information...
commit 62ac95af73dbd7f42bb907e62279e6bf077ef2fa 1 parent 1d38644
@binarylogic authored
View
2  CHANGELOG.rdoc
@@ -11,6 +11,8 @@
* Moved crypto providers into their own module and added a Sha1 provider to help with the restful_authentication transition.
* Allow the unique_token method to use the alternate crypto_provider if it is a hash algorithm, otherwise default to Sha512.
* Added last_request_at_threshold configuration option.
+* Changed Scoped class to AuthenticatesManyAssociation, like AR has HasManyAssociation, etc.
+* Added should_be_authentic shoulda macro.
== 1.0.0 released 2008-11-05
View
5 README.rdoc
@@ -1,6 +1,6 @@
= Authlogic
-Authlogic is a clean, simple, and unobtrusive ruby authentication solution. Put simply, its the Chuck Norris of authentication solutions for rails, merb, etc.
+Authlogic is a clean, simple, and unobtrusive ruby authentication solution. Put simply, its the Chuck Norris of authentication solutions for your framework of choice.
The last thing we need is another authentication solution, right? That's what I thought until I tried out some of the current solutions in both rails and merb. None of them felt right. They were either too complicated, bloated, littered my application with tons of code, or were just confusing. This is not the simple / elegant ruby we all fell in love with. We need a "ruby like" authentication solution. Authlogic is my attempt to satisfy that need...
@@ -75,11 +75,12 @@ Install the gem / plugin (recommended)
$ sudo gem install authlogic
+Now add the gem dependency in your config:
# config/environment.rb
config.gem :authlogic
-Or as a plugin (for older versions of rails)
+Or you install this as a plugin (for older versions of rails)
script/plugin install git://github.com/binarylogic/authlogic.git
View
4 lib/authlogic.rb
@@ -18,7 +18,7 @@
require File.dirname(__FILE__) + "/authlogic/orm_adapters/active_record_adapter/authenticates_many"
end
-require File.dirname(__FILE__) + "/authlogic/session/scoped"
+require File.dirname(__FILE__) + "/authlogic/session/authenticates_many_association"
require File.dirname(__FILE__) + "/authlogic/session/active_record_trickery"
require File.dirname(__FILE__) + "/authlogic/session/callbacks"
require File.dirname(__FILE__) + "/authlogic/session/config"
@@ -28,6 +28,8 @@
require File.dirname(__FILE__) + "/authlogic/session/scopes"
require File.dirname(__FILE__) + "/authlogic/session/base"
+require File.dirname(__FILE__) + "/authlogic/testing/shoulda_macros"
+
module Authlogic
module Session
class Base
View
2  lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb
@@ -46,7 +46,7 @@ def authenticates_many(name, options = {})
def #{name}
find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.scope(:find)
find_options.delete_if { |key, value| ![:conditions, :include, :joins].include?(key.to_sym) || value.nil? }
- @#{name} ||= Authlogic::Session::Scoped.new(#{options[:session_class]}, find_options, #{options[:scope_cookies] ? "self.class.model_name.underscore + '_' + self.send(self.class.primary_key).to_s" : "nil"})
+ @#{name} ||= Authlogic::Session::AuthenticatesManyAssociation.new(#{options[:session_class]}, find_options, #{options[:scope_cookies] ? "self.class.model_name.underscore + '_' + self.send(self.class.primary_key).to_s" : "nil"})
end
end_eval
end
View
10 lib/authlogic/session/scoped.rb → ...session/authenticates_many_association.rb
@@ -1,21 +1,23 @@
module Authlogic
module Session
- # This allows you to "save" scope details and call them on an object. This is mainly used for authenticates_many. This allow you to do the following:
+ # = Authenticates Many Association
+ #
+ # This object is used as a proxy for the authenticates_many relationship. It basically allows you to "save" scope details and call them on an object, which allows you to do the following:
#
# @account.user_sessions.new
# @account.user_sessions.find
# # ... etc
#
# You can call all of the class level methods off of an object with a saved scope, so that calling the above methods scopes the user sessions down to that specific account.
- class Scoped # :nodoc:
+ class AuthenticatesManyAssociation # :nodoc:
attr_accessor :klass, :find_options, :id
-
+
def initialize(klass, find_options, id)
self.klass = klass
self.find_options = find_options
self.id = id
end
-
+
[:create, :create!, :find, :new].each do |method|
class_eval <<-"end_eval", __FILE__, __LINE__
def #{method}(*args)
View
17 lib/authlogic/testing/shoulda_macros.rb
@@ -0,0 +1,17 @@
+require "test/unit"
+
+module Authlogic
+ module Testing
+ module ShouldaMacros
+ def should_be_authentic(model)
+ should "acts as authentic" do
+ assert model.respond_to?(:unique_token)
+ assert model.respond_to?(:forget_all!)
+ assert model.respond_to?(:crypto_provider)
+ end
+ end
+ end
+ end
+end
+
+Test::Unit::TestCase.extend Authlogic::Testing::ShouldaMacros
Please sign in to comment.
Something went wrong with that request. Please try again.