Skip to content
This repository
Browse code

Fix compatibility issue with rails >3.0 wanting the model_name class …

…method
  • Loading branch information...
commit faa063f84fe8f48d348b706ef1b92ef827fe12ac 1 parent f2f6988
Ben Johnson authored August 16, 2009
2  README.rdoc
Source Rendered
@@ -223,7 +223,7 @@ I think one of the best aspects of Authlogic is testing. For one, it cuts out <b
223 223
 
224 224
 For example, think about ActiveRecord. You don't test the internals of ActiveRecord, because the creators of ActiveRecord have already tested the internals for you. It wouldn't make sense for ActiveRecord to copy it's hundreds of tests into your applications. The same concept applies to Authlogic. You only need to test code you write that is specific to your application, just like everything else in your application.
225 225
 
226  
-That being said, testing your code that uses Authlogic is easy. Since everyone uses different testing suites, I created a helpful module called Authlogic::TestCase, which is basically a set of tools for testing code using Authlogic. I explain testing Authlogic thoroughly in the {Authlogic::TestCase section of the documentation}[http://authlogic.rubyforge.org/classes/Authlogic/TestCase.html]. It should answer any questions you have in regards to testing Authlogic.
  226
+That being said, testing your code that uses Authlogic is easy. Since everyone uses different testing suites, I created a helpful module called Authlogic::TestCase, which is basically a set of tools for testing code using Authlogic. I explain testing Authlogic thoroughly in the {Authlogic::TestCase section of the documentation}[http://rdoc.info/rdoc/binarylogic/authlogic/blob/f2f6988d3b97e11770b00b72a7a9733df69ffa5b/Authlogic/TestCase.html]. It should answer any questions you have in regards to testing Authlogic.
227 227
 
228 228
 == Tell me quickly how Authlogic works
229 229
 
13  Rakefile
@@ -12,6 +12,7 @@ begin
12 12
     gem.rubyforge_project = "authlogic"
13 13
     gem.add_dependency "activesupport"
14 14
   end
  15
+  Jeweler::RubyforgeTasks.new
15 16
 rescue LoadError
16 17
   puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17 18
 end
@@ -36,14 +37,6 @@ rescue LoadError
36 37
   end
37 38
 end
38 39
 
39  
-task :default => :test
  40
+task :test => :check_dependencies
40 41
 
41  
-begin
42  
-  require 'rake/contrib/sshpublisher'
43  
-  namespace :rubyforge do
44  
-    desc "Release gem to RubyForge"
45  
-    task :release => ["rubyforge:release:gem"]
46  
-  end
47  
-rescue LoadError
48  
-  puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
49  
-end
  42
+task :default => :test
1  lib/authlogic.rb
@@ -7,6 +7,7 @@
7 7
 require File.dirname(__FILE__) + "/authlogic/controller_adapters/abstract_adapter"
8 8
 require File.dirname(__FILE__) + "/authlogic/controller_adapters/rails_adapter" if defined?(Rails)
9 9
 require File.dirname(__FILE__) + "/authlogic/controller_adapters/merb_adapter" if defined?(Merb)
  10
+require File.dirname(__FILE__) + "/authlogic/controller_adapters/sinatra_adapter" if defined?(Sinatra)
10 11
 
11 12
 require File.dirname(__FILE__) + "/authlogic/crypto_providers/md5"
12 13
 require File.dirname(__FILE__) + "/authlogic/crypto_providers/sha1"
61  lib/authlogic/controller_adapters/sinatra_adapter.rb
... ...
@@ -0,0 +1,61 @@
  1
+# Authlogic bridge for Sinatra
  2
+module Authlogic
  3
+  module ControllerAdapters
  4
+    module SinatraAdapter
  5
+      class Cookies
  6
+        attr_reader :request, :response
  7
+
  8
+        def initialize(request, response)
  9
+          @request = request
  10
+          @response = response
  11
+        end
  12
+
  13
+        def delete(key, options = {})
  14
+          @request.cookies.delete(key)
  15
+        end
  16
+
  17
+        def []=(key, options)
  18
+          @response.set_cookie(key, options)
  19
+        end
  20
+
  21
+        def method_missing(meth, *args, &block)
  22
+          @request.cookies.send(meth, *args, &block)
  23
+        end
  24
+      end
  25
+
  26
+      class Controller
  27
+        attr_reader :request, :response, :cookies
  28
+
  29
+        def initialize(request, response)
  30
+          @request = request
  31
+          @cookies = Cookies.new(request, response)
  32
+        end
  33
+
  34
+        def session
  35
+          env['rack.session']
  36
+        end
  37
+
  38
+        def method_missing(meth, *args, &block)
  39
+          @request.send meth, *args, &block
  40
+        end
  41
+      end
  42
+
  43
+      class Adapter < AbstractAdapter
  44
+        def cookie_domain
  45
+          env['SERVER_NAME']
  46
+        end
  47
+
  48
+        module Implementation
  49
+          def self.included(klass)
  50
+            klass.send :before do
  51
+              controller = Controller.new(request, response)
  52
+              Authlogic::Session::Base.controller = Adapter.new(controller)
  53
+            end
  54
+          end
  55
+        end
  56
+      end
  57
+    end
  58
+  end
  59
+end
  60
+
  61
+Sinatra::Request.send(:include, Authlogic::ControllerAdapters::SinatraAdapter::Adapter::Implementation)
2  lib/authlogic/session/active_record_trickery.rb
@@ -39,7 +39,7 @@ def self_and_descendants_from_active_record
39 39
         end
40 40
         
41 41
         # For rails >3.0
42  
-        def self.model_name
  42
+        def model_name
43 43
           ActiveModel::Name.new(self.to_s)
44 44
         end
45 45
       end

0 notes on commit faa063f

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