Commit 6e62a1c18af6636e40230b6ab9689854ec8d3839
1 parent
ee8fd9e4
Exists in
master
and in
11 other branches
rails4: fix support for ruby 1.9
Showing
4 changed files
with
13 additions
and
12 deletions
Show diff stats
.travis.yml
| ... | ... | @@ -19,7 +19,7 @@ addons: |
| 19 | 19 | |
| 20 | 20 | # workaround for https://github.com/travis-ci/travis-ci/issues/4536 |
| 21 | 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 | 23 | - gem install bundler |
| 24 | 24 | cache: bundler |
| 25 | 25 | ... | ... |
lib/authenticated_system.rb
| ... | ... | @@ -4,19 +4,11 @@ module AuthenticatedSystem |
| 4 | 4 | |
| 5 | 5 | def self.included base |
| 6 | 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 | 9 | # Inclusion hook to make #current_user and #logged_in? |
| 18 | 10 | # available as ActionView helper methods. |
| 19 | - base.send :helper_method, :current_user, :logged_in? | |
| 11 | + base.helper_method :current_user, :logged_in? | |
| 20 | 12 | end |
| 21 | 13 | |
| 22 | 14 | # Returns true or false if the user is logged in. |
| ... | ... | @@ -48,6 +40,14 @@ module AuthenticatedSystem |
| 48 | 40 | @current_user = User.current = new_user |
| 49 | 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 | 51 | # Check if the user is authorized. |
| 52 | 52 | # |
| 53 | 53 | # Override this method in your controllers if you want to restrict access | ... | ... |
plugins/metadata/test/functional/content_viewer_controller_test.rb
test/functional/application_controller_test.rb
| ... | ... | @@ -194,7 +194,7 @@ class ApplicationControllerTest < ActionController::TestCase |
| 194 | 194 | User.expects(:current=).with do |user| |
| 195 | 195 | user == testuser |
| 196 | 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 | 198 | get :index |
| 199 | 199 | end |
| 200 | 200 | ... | ... |