Commit 6e62a1c18af6636e40230b6ab9689854ec8d3839

Authored by Braulio Bhavamitra
1 parent ee8fd9e4

rails4: fix support for ruby 1.9

@@ -19,7 +19,7 @@ addons: @@ -19,7 +19,7 @@ addons:
19 19
20 # workaround for https://github.com/travis-ci/travis-ci/issues/4536 20 # workaround for https://github.com/travis-ci/travis-ci/issues/4536
21 before_install: 21 before_install:
22 - - export GEM_HOME=$PWD/vendor/bundle/ruby/2.1.0 22 + - export GEM_HOME=$PWD/vendor/bundle/ruby/1.9.1
23 - gem install bundler 23 - gem install bundler
24 cache: bundler 24 cache: bundler
25 25
lib/authenticated_system.rb
@@ -4,19 +4,11 @@ module AuthenticatedSystem @@ -4,19 +4,11 @@ module AuthenticatedSystem
4 4
5 def self.included base 5 def self.included base
6 # See impl. from http://stackoverflow.com/a/2513456/670229 6 # See impl. from http://stackoverflow.com/a/2513456/670229
7 - base.around_filter do |&block|  
8 - begin  
9 - User.current = current_user  
10 - block.call  
11 - ensure  
12 - # to address the thread variable leak issues in Puma/Thin webserver  
13 - User.current = nil  
14 - end  
15 - end if base.is_a? ActionController::Base 7 + base.around_filter :user_set_current if base.is_a? ActionController::Base
16 8
17 # Inclusion hook to make #current_user and #logged_in? 9 # Inclusion hook to make #current_user and #logged_in?
18 # available as ActionView helper methods. 10 # available as ActionView helper methods.
19 - base.send :helper_method, :current_user, :logged_in? 11 + base.helper_method :current_user, :logged_in?
20 end 12 end
21 13
22 # Returns true or false if the user is logged in. 14 # Returns true or false if the user is logged in.
@@ -48,6 +40,14 @@ module AuthenticatedSystem @@ -48,6 +40,14 @@ module AuthenticatedSystem
48 @current_user = User.current = new_user 40 @current_user = User.current = new_user
49 end 41 end
50 42
  43 + def user_set_current
  44 + User.current = current_user
  45 + yield
  46 + ensure
  47 + # to address the thread variable leak issues in Puma/Thin webserver
  48 + User.current = nil
  49 + end
  50 +
51 # Check if the user is authorized. 51 # Check if the user is authorized.
52 # 52 #
53 # Override this method in your controllers if you want to restrict access 53 # Override this method in your controllers if you want to restrict access
plugins/metadata/test/functional/content_viewer_controller_test.rb
  1 +# encoding: UTF-8
1 require 'test_helper' 2 require 'test_helper'
2 require 'content_viewer_controller' 3 require 'content_viewer_controller'
3 4
test/functional/application_controller_test.rb
@@ -194,7 +194,7 @@ class ApplicationControllerTest < ActionController::TestCase @@ -194,7 +194,7 @@ class ApplicationControllerTest < ActionController::TestCase
194 User.expects(:current=).with do |user| 194 User.expects(:current=).with do |user|
195 user == testuser 195 user == testuser
196 end.at_least_once 196 end.at_least_once
197 - User.expects(:current=).with(nil).at_least_once 197 + User.expects(:current=).with(nil).at_least_once if RUBY_VERSION >= '2.0'
198 get :index 198 get :index
199 end 199 end
200 200