From 6e62a1c18af6636e40230b6ab9689854ec8d3839 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Fri, 11 Sep 2015 13:47:49 -0300 Subject: [PATCH] rails4: fix support for ruby 1.9 --- .travis.yml | 2 +- lib/authenticated_system.rb | 20 ++++++++++---------- plugins/metadata/test/functional/content_viewer_controller_test.rb | 1 + test/functional/application_controller_test.rb | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78f4a99..b5dc618 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ addons: # workaround for https://github.com/travis-ci/travis-ci/issues/4536 before_install: - - export GEM_HOME=$PWD/vendor/bundle/ruby/2.1.0 + - export GEM_HOME=$PWD/vendor/bundle/ruby/1.9.1 - gem install bundler cache: bundler diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb index fade8e8..245a77b 100644 --- a/lib/authenticated_system.rb +++ b/lib/authenticated_system.rb @@ -4,19 +4,11 @@ module AuthenticatedSystem def self.included base # See impl. from http://stackoverflow.com/a/2513456/670229 - base.around_filter do |&block| - begin - User.current = current_user - block.call - ensure - # to address the thread variable leak issues in Puma/Thin webserver - User.current = nil - end - end if base.is_a? ActionController::Base + base.around_filter :user_set_current if base.is_a? ActionController::Base # Inclusion hook to make #current_user and #logged_in? # available as ActionView helper methods. - base.send :helper_method, :current_user, :logged_in? + base.helper_method :current_user, :logged_in? end # Returns true or false if the user is logged in. @@ -48,6 +40,14 @@ module AuthenticatedSystem @current_user = User.current = new_user end + def user_set_current + User.current = current_user + yield + ensure + # to address the thread variable leak issues in Puma/Thin webserver + User.current = nil + end + # Check if the user is authorized. # # Override this method in your controllers if you want to restrict access diff --git a/plugins/metadata/test/functional/content_viewer_controller_test.rb b/plugins/metadata/test/functional/content_viewer_controller_test.rb index ae5f5fd..58e4d20 100644 --- a/plugins/metadata/test/functional/content_viewer_controller_test.rb +++ b/plugins/metadata/test/functional/content_viewer_controller_test.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require 'test_helper' require 'content_viewer_controller' diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 787fc52..cd4afec 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -194,7 +194,7 @@ class ApplicationControllerTest < ActionController::TestCase User.expects(:current=).with do |user| user == testuser end.at_least_once - User.expects(:current=).with(nil).at_least_once + User.expects(:current=).with(nil).at_least_once if RUBY_VERSION >= '2.0' get :index end -- libgit2 0.21.2