diff --git a/lib/devise/controllers/authenticable.rb b/lib/devise/controllers/authenticable.rb index c9b3961c..9fa2cfbe 100644 --- a/lib/devise/controllers/authenticable.rb +++ b/lib/devise/controllers/authenticable.rb @@ -6,13 +6,7 @@ module Devise def self.included(base) base.class_eval do - helper_method :warden, :user, :logged_in? -# helper_method :session_path, :session_url, -# :new_session_path, :new_session_url, -# :password_path, :password_url, -# :new_password_path, :new_password_url, -# :confirmation_path, :confirmation_url, -# :new_confirmation_path, :new_confirmation_url + helper_method :warden, :current_user, :signed_in? end end @@ -27,21 +21,19 @@ module Devise def authenticated?(scope=:default) warden.authenticated?(scope.to_sym) end - alias_method :logged_in?, :authenticated? + alias_method :signed_in?, :authenticated? - # Access the currently logged in user + # Access the currently logged in user based on the scope # - def user - warden.user(resource_name) + def current_user(scope=resource_name) + warden.user(scope) end - alias_method :current_user, :user - def user=(user) + def current_user=(user) warden.set_user(user, :scope => resource_name) end - alias_method :current_user=, :user= - # Logout the current user + # Logout the current user based on scope # def logout warden.raw_session.inspect # Without this inspect here. The session does not clear :| diff --git a/lib/devise/controllers/url_helpers.rb b/lib/devise/controllers/url_helpers.rb index 396afcf9..8f93fcee 100644 --- a/lib/devise/controllers/url_helpers.rb +++ b/lib/devise/controllers/url_helpers.rb @@ -2,18 +2,6 @@ module Devise module Controllers module UrlHelpers -# def self.included(base) -# base.class_eval do -# helper_method :session_path, :session_url, -# :new_session_path, :new_session_url, -# :password_path, :password_url, -# :new_password_path, :new_password_url, -# :edit_password_path, :edit_password_url, -# :confirmation_path, :confirmation_url, -# :new_confirmation_path, :new_confirmation_url -# end -# end - # TODO: refactor url helpers generation [:session, :password, :confirmation].each do |module_name| [:path, :url].each do |path_or_url| @@ -31,62 +19,6 @@ module Devise end end end - -# def new_session_path(*args) -# send("new_#{resource_name}_session_path", *args) -# end - -# def new_session_url(*args) -# send("new_#{resource_name}_session_url", *args) -# end - -# def session_path(*args) -# send("#{resource_name}_session_path", *args) -# end - -# def session_url(*args) -# send("#{resource_name}_session_url", *args) -# end - -# def new_confirmation_path(*args) -# send("new_#{resource_name}_confirmation_path", *args) -# end - -# def new_confirmation_url(*args) -# send("new_#{resource_name}_confirmation_url", *args) -# end - -# def confirmation_path(*args) -# send("#{resource_name}_confirmation_path", *args) -# end - -# def confirmation_url(*args) -# send("#{resource_name}_confirmation_url", *args) -# end - -# def new_password_path(*args) -# send("new_#{resource_name}_password_path", *args) -# end - -# def new_password_url(*args) -# send("new_#{resource_name}_password_url", *args) -# end - -# def password_path(*args) -# send("#{resource_name}_password_path", *args) -# end - -# def password_url(*args) -# send("#{resource_name}_password_url", *args) -# end - -# def edit_password_path(*args) -# send("edit_#{resource_name}_password_path", *args) -# end - -# def edit_password_url(*args) -# send("edit_#{resource_name}_password_url", *args) -# end end end end diff --git a/test/controllers/authenticable_test.rb b/test/controllers/authenticable_test.rb index 900b6918..182fc2a4 100644 --- a/test/controllers/authenticable_test.rb +++ b/test/controllers/authenticable_test.rb @@ -38,24 +38,24 @@ class ControllerAuthenticableTest < ActionController::TestCase @controller.authenticated?(:my_scope) end - test 'proxy logged_in? to authenticated' do + test 'proxy signed_in? to authenticated' do @mock_warden.expects(:authenticated?).with(:my_scope) - @controller.logged_in?(:my_scope) + @controller.signed_in?(:my_scope) end test 'run user on warden' do @mock_warden.expects(:user).returns(true) - @controller.user + @controller.current_user end - test 'run current_user on warden' do - @mock_warden.expects(:user).returns(true) - @controller.current_user + test 'run user with scope on warden' do + @mock_warden.expects(:user).with(:admin).returns(true) + @controller.current_user(:admin) end test 'set the user on warden' do @mock_warden.expects(:set_user).returns(true) - @controller.user = User.new + @controller.current_user = User.new end test 'proxy logout to warden' do