diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb index 71d21e2..d001a1b 100644 --- a/lib/authenticated_system.rb +++ b/lib/authenticated_system.rb @@ -2,17 +2,21 @@ module AuthenticatedSystem protected - # See impl. from http://stackoverflow.com/a/2513456/670229 - def self.included? base - base.around_filter do + def self.included base + # See impl. from http://stackoverflow.com/a/2513456/670229 + base.around_filter do |&block| begin User.current = current_user - yield + block.call ensure # to address the thread variable leak issues in Puma/Thin webserver User.current = nil end end + + # Inclusion hook to make #current_user and #logged_in? + # available as ActionView helper methods. + base.send :helper_method, :current_user, :logged_in? end # Returns true or false if the user is logged in. @@ -134,12 +138,6 @@ module AuthenticatedSystem end end - # Inclusion hook to make #current_user and #logged_in? - # available as ActionView helper methods. - def self.included(base) - base.send :helper_method, :current_user, :logged_in? - end - # When called with before_filter :login_from_cookie will check for an :auth_token # cookie and log the user back in if apropriate def login_from_cookie diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index baa8aac..efd4ffb 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -191,6 +191,16 @@ class ApplicationControllerTest < ActionController::TestCase assert_tag :tag => 'option', :attributes => { :value => 'it' }, :content => 'Italiano' end + should 'set and unset the current user' do + testuser = create_user 'testuser' + login_as 'testuser' + User.expects(:current=).with do |user| + user == testuser + end.at_least_once + User.expects(:current=).with(nil).at_least_once + get :index + end + should 'display link to webmail if enabled for system' do @controller.stubs(:get_layout).returns('application') login_as('ze') -- libgit2 0.21.2