Skip to content

Loading…

Added a option to not run callbacks on Proxy #41

Merged
merged 2 commits into from

2 participants

@rodrigoflores

Hi

I have added an option to not run callbacks on Proxy methods.

Rodrigo Flores added some commits
@josevalim josevalim merged commit fb74780 into hassox:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 15, 2012
  1. Added a run_callbacks options to proxy

    Rodrigo Flores committed
  2. Adding a few more tests

    Rodrigo Flores committed
Showing with 31 additions and 2 deletions.
  1. +4 −2 lib/warden/proxy.rb
  2. +27 −0 spec/warden/proxy_spec.rb
View
6 lib/warden/proxy.rb
@@ -160,8 +160,10 @@ def set_user(user, opts = {})
options[:renew] = true if options
session_serializer.store(user, scope)
end
-
- manager._run_callbacks(:after_set_user, user, self, opts)
+
+ run_callbacks = opts.fetch(:run_callbacks, true)
+
+ manager._run_callbacks(:after_set_user, user, self, opts) if run_callbacks
@users[scope]
end
View
27 spec/warden/proxy_spec.rb
@@ -365,6 +365,33 @@
end
setup_rack(app).call(@env)
end
+
+ it "should not run the callbacks when :run_callbacks is false" do
+ app = lambda do |env|
+ env['warden'].manager.should_not_receive(:_run_callbacks)
+ env['warden'].authenticate(:pass, :run_callbacks => false)
+ valid_response
+ end
+ setup_rack(app).call(@env)
+ end
+
+ it "should run the callbacks when :run_callbacks is true" do
+ app = lambda do |env|
+ env['warden'].manager.should_receive(:_run_callbacks)
+ env['warden'].authenticate(:pass, :run_callbacks => true)
+ valid_response
+ end
+ setup_rack(app).call(@env)
+ end
+
+ it "should run the callbacks by default" do
+ app = lambda do |env|
+ env['warden'].manager.should_receive(:_run_callbacks)
+ env['warden'].authenticate(:pass)
+ valid_response
+ end
+ setup_rack(app).call(@env)
+ end
end
describe "get user" do
Something went wrong with that request. Please try again.