aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2015-09-08 11:43:10 -0400
committereileencodes <eileencodes@gmail.com>2015-09-09 09:04:44 -0400
commit43d7a03aef737787d4166fe347f40d901f6334c3 (patch)
tree795ea027cc6bd51f77dee78211ad314114c69684 /actionpack/lib/action_controller
parentd73d1a26b342b2323a58b55021eb8701790ada2a (diff)
downloadrails-43d7a03aef737787d4166fe347f40d901f6334c3.tar.gz
rails-43d7a03aef737787d4166fe347f40d901f6334c3.tar.bz2
rails-43d7a03aef737787d4166fe347f40d901f6334c3.zip
Handle Content-Types that are not :json, :xml, or :url_encoded_form
In c546a2b this was changed to mimic how the browser behaves in a real situation but left out types that were registered. When this was changed it didn't take `text/plain` or `text/html` content types into account. This is a problem if you're manipulating the `Content-Type` headers in your controller tests, and expect a certain result. The reason I changed this to use `to_sym` is because if the `Content-Type` is not registered then the symbol will not exist. If it's one of the special types we handle that specifically (:json, :xml, or :url_encoded_form). If it's any registered type we handle it by setting the `path_parameters` and then the `request_parameters`. If the `to_sym` returns nil an error will be thrown. If the controller test sets a `Content-Type` on the request that `Content-Type` should remain in the header and pass along the filename. For example: If a test sets a content type on a post ``` @request.headers['CONTENT_TYPE'] = 'text/plain' post :create, params: { name: 'foo.txt' } ``` Then `foo.txt` should be in the `request_parameters` and params related to the path should be in the `path_parameters` and the `Content-Type` header should match the one set in the `@request`. When c546a2b was committed `text/plain` and `text/html` types were throwing a "Unknown Content-Type" error which is misleading and incorrect. Note: this does not affect how this is handled in the browser, just how the controller tests handle setting `Content-Type`.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/test_case.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 472bb74add..fbbaa1a887 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -78,7 +78,9 @@ module ActionController
# params parser middleware, and we should remove this roundtripping
# when we switch to caling `call` on the controller
- case content_mime_type.ref
+ case content_mime_type.to_sym
+ when nil
+ raise "Unknown Content-Type: #{content_type}"
when :json
data = ActiveSupport::JSON.encode(non_path_parameters)
params = ActiveSupport::JSON.decode(data).with_indifferent_access
@@ -90,7 +92,8 @@ module ActionController
when :url_encoded_form
data = non_path_parameters.to_query
else
- raise "Unknown Content-Type: #{content_type}"
+ data = non_path_parameters.to_query
+ self.request_parameters = non_path_parameters
end
end