Permalink
Browse files

Updates to fix issue 3. Thanx vandrijevik (Vladimir Andrijevik) and t…

…mm1 (Aman Gupta)
  • Loading branch information...
1 parent 4b6248e commit 35de07f46ccdf11970bae8ece0307d6b1f538c6e @hassox hassox committed Nov 17, 2009
Showing with 30 additions and 18 deletions.
  1. +9 −1 lib/rails_warden.rb
  2. +6 −13 lib/rails_warden/manager.rb
  3. +5 −4 rails_warden.gemspec
  4. +10 −0 spec/rails_warden_spec.rb
View
10 lib/rails_warden.rb
@@ -21,7 +21,7 @@ def request
def raw_session
request.session
end
-
+
def reset_session!
raw_session.inspect # why do I have to inspect it to get it to clear?
raw_session.clear
@@ -32,6 +32,14 @@ def reset_session!
env['warden'].request.params['action'] = RailsWarden.unauthenticated_action || "unauthenticated"
end
+# Rails needs the action to be passed in with the params
+Warden::Manager.before_failure do |env, opts|
+ if request = env["action_controller.rescue.request"]
+ request.params["action"] = RailsWarden.unauthenticated_action
+ end
+end
+
+
if defined?(Rails)
Rails.configuration.after_initialize do
class ActionController::Base
View
19 lib/rails_warden/manager.rb
@@ -1,31 +1,24 @@
# encoding: utf-8
module RailsWarden
class Manager
-
+
def self.new(app, opts = {}, &block)
# Get the failure application
opts[:failure_app] = opts[:failure_app].to_s.classify.constantize if opts[:failure_app]
opts[:default_strategies] = [opts[:defaults]].flatten if opts[:defaults]
-
+
# Set the default user
if user = opts.delete(:default_user)
RailsWarden.default_user_class = user.to_s.classify.constantize
end
-
+
# Set the unauthenticated action if it's set
if ua = opts.delete(:unauthenticated_action)
RailsWarden.unauthenticated_action = ua
end
-
- # Rails needs the action to be passed in with the params
- Warden::Manager.before_failure do |env, opts|
- if request = env["action_controller.rescue.request"]
- request.params["action"] = RailsWarden.unauthenticated_action
- end
- end
-
+
Warden::Manager.new(app, opts, &block)
end
-
+
end
-end
+end
View
9 rails_warden.gemspec
@@ -1,15 +1,15 @@
# Generated by jeweler
-# DO NOT EDIT THIS FILE
-# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{rails_warden}
- s.version = "0.2.4"
+ s.version = "0.2.5"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Daniel Neighman"]
- s.date = %q{2009-09-09}
+ s.date = %q{2009-11-17}
s.description = %q{A gem that provides authenitcation via the Warden framework}
s.email = %q{has.sox@gmail.com}
s.extra_rdoc_files = [
@@ -57,3 +57,4 @@ Gem::Specification.new do |s|
else
end
end
+
View
10 spec/rails_warden_spec.rb
@@ -54,4 +54,14 @@ class ::User
)
RailsWarden.unauthenticated_action.should == "unauthenticated"
end
+
+ it "should not add a before_failure callback each time it is created" do
+ original_number_of_callbacks = Warden::Manager._before_failure.size
+
+ RailsWarden::Manager.new(@app, :failure_app => "foo_failure",
+ :defaults => :password)
+
+ Warden::Manager._before_failure.size.should == original_number_of_callbacks
+ end
+
end

0 comments on commit 35de07f

Please sign in to comment.