Skip to content
This repository
Browse code

Added should_be_authentic shoulda macro

  • Loading branch information...
commit 62ac95af73dbd7f42bb907e62279e6bf077ef2fa 1 parent 1d38644
Ben Johnson yourewelcome authored
2  CHANGELOG.rdoc
Source Rendered
@@ -11,6 +11,8 @@
11 11 * Moved crypto providers into their own module and added a Sha1 provider to help with the restful_authentication transition.
12 12 * Allow the unique_token method to use the alternate crypto_provider if it is a hash algorithm, otherwise default to Sha512.
13 13 * Added last_request_at_threshold configuration option.
  14 +* Changed Scoped class to AuthenticatesManyAssociation, like AR has HasManyAssociation, etc.
  15 +* Added should_be_authentic shoulda macro.
14 16
15 17 == 1.0.0 released 2008-11-05
16 18
5 README.rdoc
Source Rendered
... ... @@ -1,6 +1,6 @@
1 1 = Authlogic
2 2
3   -Authlogic is a clean, simple, and unobtrusive ruby authentication solution. Put simply, its the Chuck Norris of authentication solutions for rails, merb, etc.
  3 +Authlogic is a clean, simple, and unobtrusive ruby authentication solution. Put simply, its the Chuck Norris of authentication solutions for your framework of choice.
4 4
5 5 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...
6 6
@@ -75,11 +75,12 @@ Install the gem / plugin (recommended)
75 75
76 76 $ sudo gem install authlogic
77 77
  78 +Now add the gem dependency in your config:
78 79
79 80 # config/environment.rb
80 81 config.gem :authlogic
81 82
82   -Or as a plugin (for older versions of rails)
  83 +Or you install this as a plugin (for older versions of rails)
83 84
84 85 script/plugin install git://github.com/binarylogic/authlogic.git
85 86
4 lib/authlogic.rb
@@ -18,7 +18,7 @@
18 18 require File.dirname(__FILE__) + "/authlogic/orm_adapters/active_record_adapter/authenticates_many"
19 19 end
20 20
21   -require File.dirname(__FILE__) + "/authlogic/session/scoped"
  21 +require File.dirname(__FILE__) + "/authlogic/session/authenticates_many_association"
22 22 require File.dirname(__FILE__) + "/authlogic/session/active_record_trickery"
23 23 require File.dirname(__FILE__) + "/authlogic/session/callbacks"
24 24 require File.dirname(__FILE__) + "/authlogic/session/config"
@@ -28,6 +28,8 @@
28 28 require File.dirname(__FILE__) + "/authlogic/session/scopes"
29 29 require File.dirname(__FILE__) + "/authlogic/session/base"
30 30
  31 +require File.dirname(__FILE__) + "/authlogic/testing/shoulda_macros"
  32 +
31 33 module Authlogic
32 34 module Session
33 35 class Base
2  lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb
@@ -46,7 +46,7 @@ def authenticates_many(name, options = {})
46 46 def #{name}
47 47 find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.scope(:find)
48 48 find_options.delete_if { |key, value| ![:conditions, :include, :joins].include?(key.to_sym) || value.nil? }
49   - @#{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"})
  49 + @#{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"})
50 50 end
51 51 end_eval
52 52 end
10 lib/authlogic/session/scoped.rb → ...thlogic/session/authenticates_many_association.rb
... ... @@ -1,21 +1,23 @@
1 1 module Authlogic
2 2 module Session
3   - # 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:
  3 + # = Authenticates Many Association
  4 + #
  5 + # 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:
4 6 #
5 7 # @account.user_sessions.new
6 8 # @account.user_sessions.find
7 9 # # ... etc
8 10 #
9 11 # 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.
10   - class Scoped # :nodoc:
  12 + class AuthenticatesManyAssociation # :nodoc:
11 13 attr_accessor :klass, :find_options, :id
12   -
  14 +
13 15 def initialize(klass, find_options, id)
14 16 self.klass = klass
15 17 self.find_options = find_options
16 18 self.id = id
17 19 end
18   -
  20 +
19 21 [:create, :create!, :find, :new].each do |method|
20 22 class_eval <<-"end_eval", __FILE__, __LINE__
21 23 def #{method}(*args)
17 lib/authlogic/testing/shoulda_macros.rb
... ... @@ -0,0 +1,17 @@
  1 +require "test/unit"
  2 +
  3 +module Authlogic
  4 + module Testing
  5 + module ShouldaMacros
  6 + def should_be_authentic(model)
  7 + should "acts as authentic" do
  8 + assert model.respond_to?(:unique_token)
  9 + assert model.respond_to?(:forget_all!)
  10 + assert model.respond_to?(:crypto_provider)
  11 + end
  12 + end
  13 + end
  14 + end
  15 +end
  16 +
  17 +Test::Unit::TestCase.extend Authlogic::Testing::ShouldaMacros

0 comments on commit 62ac95a

Please sign in to comment.
Something went wrong with that request. Please try again.