diff options
author | Kir Shatrov <shatrov@me.com> | 2016-09-22 11:36:23 -0400 |
---|---|---|
committer | Kir Shatrov <shatrov@me.com> | 2016-09-22 11:36:23 -0400 |
commit | 7e350c67057affccde176eeeffcffbe10806feda (patch) | |
tree | 40728e9380876d85dce75797b8b2d648af4fb095 /actionpack | |
parent | cf5f55cd30aef0f90300c7c8f333060fe258cd8a (diff) | |
download | rails-7e350c67057affccde176eeeffcffbe10806feda.tar.gz rails-7e350c67057affccde176eeeffcffbe10806feda.tar.bz2 rails-7e350c67057affccde176eeeffcffbe10806feda.zip |
Fix memoization bug on ActionDispatch::TestRequest#request_method=
TestRequest have been overrriding request_method setter since 2009,
but the actual implementation in Request (not TestRequest) has been
changed since that. Now it's also using @request_method instance
variable to keep the state.
The override in TestRequest have not been calling `super`, which caused
a bug that after accessing #requst_method the value was memoized and
then we've never been able to change it anymore:
```
req = ActionDispatch::TestRequest.create
puts "was: #{req.request_method}" # memoized here
req.request_method = "POST"
puts "became: #{req.request_method}"
```
output:
```
was: GET
became: GET
```
Since the whole purpose of overriding the setter in TestRequest is to
upcase it, I'm changing it to `super(method.to_s.upcase)`
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/test_request.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/test_request_test.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index d0beb72a41..91b25ec155 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -22,7 +22,7 @@ module ActionDispatch private_class_method :default_env def request_method=(method) - set_header("REQUEST_METHOD", method.to_s.upcase) + super(method.to_s.upcase) end def host=(host) diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb index 35af3076ba..b479af781d 100644 --- a/actionpack/test/dispatch/test_request_test.rb +++ b/actionpack/test/dispatch/test_request_test.rb @@ -88,6 +88,13 @@ class TestRequestTest < ActiveSupport::TestCase assert_equal "GoogleBot", req.user_agent end + test "request_method getter and setter" do + req = ActionDispatch::TestRequest.create + req.request_method # to reproduce bug caused by memoization + req.request_method = "POST" + assert_equal "POST", req.request_method + end + test "setter methods" do req = ActionDispatch::TestRequest.create({}) get = "GET" |