aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAditya Sanghi <aditya.sanghi@risingsuntech.net>2012-12-27 19:24:16 +0530
committerAditya Sanghi <aditya.sanghi@risingsuntech.net>2013-01-16 15:59:17 +0530
commit5f3b40e824cce3f6dcdfac63fa47bcd80d67dd5a (patch)
tree6ea875a7d2f0be3b46d08a4121818e1d5196918f /actionpack
parentfd990f24df87c0a445ea6a2a2df6fa8fbd3556b1 (diff)
downloadrails-5f3b40e824cce3f6dcdfac63fa47bcd80d67dd5a.tar.gz
rails-5f3b40e824cce3f6dcdfac63fa47bcd80d67dd5a.tar.bz2
rails-5f3b40e824cce3f6dcdfac63fa47bcd80d67dd5a.zip
fixes #8631 local inflections from interfereing with HTTP_METHOD_LOOKUP dispatch logic
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md5
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb7
-rw-r--r--actionpack/test/dispatch/request_test.rb21
3 files changed, 32 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index eca24cde1a..42eced7a37 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 3.2.12 (unreleased) ##
+* Eagerly populate the http method loookup cache so local project inflections do
+ not interfere with use of underscore method ( and we don't need locks )
+
+ *Aditya Sanghi*
+
* `BestStandardsSupport` no longer duplicates `X-UA-Compatible` values on
each request to prevent header size from blowing up.
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 2fac9668c1..31155732d2 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -56,7 +56,12 @@ module ActionDispatch
RFC5789 = %w(PATCH)
HTTP_METHODS = RFC2616 + RFC2518 + RFC3253 + RFC3648 + RFC3744 + RFC5323 + RFC5789
- HTTP_METHOD_LOOKUP = Hash.new { |h, m| h[m] = m.underscore.to_sym if HTTP_METHODS.include?(m) }
+ HTTP_METHOD_LOOKUP = {}
+
+ # Populate the HTTP method lookup cache
+ HTTP_METHODS.each do |method|
+ HTTP_METHOD_LOOKUP[method] = method.underscore.to_sym
+ end
# Returns the HTTP \method that the application should see.
# In the case where the \method was overridden by a middleware
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index 56431b4daf..dfd3ddbfa6 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -371,6 +371,27 @@ class RequestTest < ActiveSupport::TestCase
assert request.put?
end
+ test "post uneffected by local inflections" do
+ existing_acrnoyms = ActiveSupport::Inflector.inflections.acronyms.dup
+ existing_acrnoym_regex = ActiveSupport::Inflector.inflections.acronym_regex.dup
+ begin
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.acronym "POS"
+ end
+ assert_equal "pos_t", "POST".underscore
+ request = stub_request "REQUEST_METHOD" => "POST"
+ assert_equal :post, ActionDispatch::Request::HTTP_METHOD_LOOKUP["POST"]
+ assert_equal :post, request.method_symbol
+ assert request.post?
+ ensure
+ # Reset original acronym set
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.send(:instance_variable_set,"@acronyms",existing_acrnoyms)
+ inflect.send(:instance_variable_set,"@acronym_regex",existing_acrnoym_regex)
+ end
+ end
+ end
+
test "xml format" do
request = stub_request
request.expects(:parameters).at_least_once.returns({ :format => 'xml' })