Permalink
Browse files

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

…method
  • Loading branch information...
1 parent f2f6988 commit faa063f84fe8f48d348b706ef1b92ef827fe12ac @binarylogic committed Aug 16, 2009
View
@@ -223,7 +223,7 @@ I think one of the best aspects of Authlogic is testing. For one, it cuts out <b
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.
-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.
+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.
== Tell me quickly how Authlogic works
View
@@ -12,6 +12,7 @@ begin
gem.rubyforge_project = "authlogic"
gem.add_dependency "activesupport"
end
+ Jeweler::RubyforgeTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
@@ -36,14 +37,6 @@ rescue LoadError
end
end
-task :default => :test
+task :test => :check_dependencies
-begin
- require 'rake/contrib/sshpublisher'
- namespace :rubyforge do
- desc "Release gem to RubyForge"
- task :release => ["rubyforge:release:gem"]
- end
-rescue LoadError
- puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
-end
+task :default => :test
View
@@ -7,6 +7,7 @@
require File.dirname(__FILE__) + "/authlogic/controller_adapters/abstract_adapter"
require File.dirname(__FILE__) + "/authlogic/controller_adapters/rails_adapter" if defined?(Rails)
require File.dirname(__FILE__) + "/authlogic/controller_adapters/merb_adapter" if defined?(Merb)
+require File.dirname(__FILE__) + "/authlogic/controller_adapters/sinatra_adapter" if defined?(Sinatra)
require File.dirname(__FILE__) + "/authlogic/crypto_providers/md5"
require File.dirname(__FILE__) + "/authlogic/crypto_providers/sha1"
@@ -0,0 +1,61 @@
+# Authlogic bridge for Sinatra
+module Authlogic
+ module ControllerAdapters
+ module SinatraAdapter
+ class Cookies
+ attr_reader :request, :response
+
+ def initialize(request, response)
+ @request = request
+ @response = response
+ end
+
+ def delete(key, options = {})
+ @request.cookies.delete(key)
+ end
+
+ def []=(key, options)
+ @response.set_cookie(key, options)
+ end
+
+ def method_missing(meth, *args, &block)
+ @request.cookies.send(meth, *args, &block)
+ end
+ end
+
+ class Controller
+ attr_reader :request, :response, :cookies
+
+ def initialize(request, response)
+ @request = request
+ @cookies = Cookies.new(request, response)
+ end
+
+ def session
+ env['rack.session']
+ end
+
+ def method_missing(meth, *args, &block)
+ @request.send meth, *args, &block
+ end
+ end
+
+ class Adapter < AbstractAdapter
+ def cookie_domain
+ env['SERVER_NAME']
+ end
+
+ module Implementation
+ def self.included(klass)
+ klass.send :before do
+ controller = Controller.new(request, response)
+ Authlogic::Session::Base.controller = Adapter.new(controller)
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+Sinatra::Request.send(:include, Authlogic::ControllerAdapters::SinatraAdapter::Adapter::Implementation)
@@ -39,7 +39,7 @@ def self_and_descendants_from_active_record
end
# For rails >3.0
- def self.model_name
+ def model_name
ActiveModel::Name.new(self.to_s)
end
end

0 comments on commit faa063f

Please sign in to comment.