Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'rails23' into all

  • Loading branch information...
commit fe4e4c4033f08ea7faee3331647b064600ab79e5 2 parents e32ac9a + e42d448
@grosser grosser authored
Showing with 52 additions and 6 deletions.
  1. +8 −6 lib/http_accept_language.rb
  2. +44 −0 test/http_accept_language_test.rb
View
14 lib/http_accept_language.rb
@@ -91,10 +91,12 @@ def language_region_compatible_from(available_languages)
end.compact.first
end
end
-if defined?(ActionDispatch::Request)
- ActionDispatch::Request.send :include, HttpAcceptLanguage
-elsif defined?(ActionDispatch::AbstractRequest)
- ActionDispatch::AbstractRequest.send :include, HttpAcceptLanguage
-elsif defined?(ActionDispatch::CgiRequest)
- ActionDispatch::CgiRequest.send :include, HttpAcceptLanguage
+
+if defined?(ActionPack)
+ classes = if ActionPack::VERSION::MAJOR == 2
+ [ActionController::Request, ActionController::CgiRequest]
+ else
+ [ActionDispatch::Request]
+ end
+ classes.each{|c| c.send :include, HttpAcceptLanguage }
end
View
44 test/http_accept_language_test.rb
@@ -2,6 +2,24 @@
require 'http_accept_language'
require 'test/unit'
+module ActionPack
+ module VERSION
+ MAJOR = 3
+ end
+end
+
+module ActionDispatch
+ class Request
+ end
+end
+
+module ActionController
+ class CgiRequest
+ end
+ class Request
+ end
+end
+
class MockedCgiRequest
include HttpAcceptLanguage
def env
@@ -52,7 +70,33 @@ def test_should_find_most_compatible_language_from_user_preferred
assert_equal "ja-JP", request.language_region_compatible_from(%w{en-UK en-US ja-JP})
end
+ def test_should_be_included_into_actionpack_v2
+ silence_warnings do
+ ActionPack::VERSION.const_set(:MAJOR, 2)
+ end
+ load "http_accept_language.rb"
+
+ assert_include ActionController::Request.ancestors, HttpAcceptLanguage
+ assert_include ActionController::CgiRequest.ancestors, HttpAcceptLanguage
+ end
+
+ def test_should_be_included_into_actionpack_v3
+ silence_warnings do
+ ActionPack::VERSION.const_set(:MAJOR, 3)
+ end
+ load "http_accept_language.rb"
+ assert_include ActionDispatch::Request.ancestors, HttpAcceptLanguage
+ end
+
private
+
+ def silence_warnings
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ yield
+ ensure
+ $VERBOSE = old_verbose
+ end
+
def request
@request ||= MockedCgiRequest.new
end
Please sign in to comment.
Something went wrong with that request. Please try again.