aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2018-12-17 10:24:38 -0500
committerGitHub <noreply@github.com>2018-12-17 10:24:38 -0500
commit02b931c764cca4c3f67b1decfc046bfb46dc510c (patch)
tree04b25f1e0daf1e3f4bf71705bd08fa5dfa51c870 /actionpack
parent07ec8062e605ba4e9bd153e1d264b02ac4ab8a0f (diff)
parent048e3172f51db1fddd03b89f676d96a443539a13 (diff)
downloadrails-02b931c764cca4c3f67b1decfc046bfb46dc510c.tar.gz
rails-02b931c764cca4c3f67b1decfc046bfb46dc510c.tar.bz2
rails-02b931c764cca4c3f67b1decfc046bfb46dc510c.zip
Merge branch 'master' into host-authorization
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md18
-rw-r--r--actionpack/lib/action_dispatch/testing/test_response.rb11
-rw-r--r--actionpack/test/controller/test_case_test.rb14
3 files changed, 37 insertions, 6 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 066e92fec3..13fbbafc0c 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -8,6 +8,24 @@
*Genadi Samokovarov*
+* Allow using `parsed_body` in `ActionController::TestCase`.
+
+ In addition to `ActionDispatch::IntegrationTest`, allow using
+ `parsed_body` in `ActionController::TestCase`:
+
+ ```
+ class SomeControllerTest < ActionController::TestCase
+ def test_some_action
+ post :action, body: { foo: 'bar' }
+ assert_equal({ "foo" => "bar" }, response.parsed_body)
+ end
+ end
+ ```
+
+ Fixes #34676.
+
+ *Tobias Bühlmann*
+
* Raise an error on root route naming conflicts.
Raises an ArgumentError when multiple root routes are defined in the
diff --git a/actionpack/lib/action_dispatch/testing/test_response.rb b/actionpack/lib/action_dispatch/testing/test_response.rb
index 1e6b21f235..7c1202dc0e 100644
--- a/actionpack/lib/action_dispatch/testing/test_response.rb
+++ b/actionpack/lib/action_dispatch/testing/test_response.rb
@@ -14,11 +14,6 @@ module ActionDispatch
new response.status, response.headers, response.body
end
- def initialize(*) # :nodoc:
- super
- @response_parser = RequestEncoder.parser(content_type)
- end
-
# Was the response successful?
def success?
ActiveSupport::Deprecation.warn(<<-MSG.squish)
@@ -47,7 +42,11 @@ module ActionDispatch
end
def parsed_body
- @parsed_body ||= @response_parser.call(body)
+ @parsed_body ||= response_parser.call(body)
+ end
+
+ def response_parser
+ @response_parser ||= RequestEncoder.parser(content_type)
end
end
end
diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb
index 6fc70d6248..c931e2daac 100644
--- a/actionpack/test/controller/test_case_test.rb
+++ b/actionpack/test/controller/test_case_test.rb
@@ -156,6 +156,10 @@ XML
render html: '<body class="foo"></body>'.html_safe
end
+ def render_json
+ render json: request.raw_post
+ end
+
def boom
raise "boom!"
end
@@ -965,6 +969,16 @@ XML
assert_equal "q=test2", @response.body
end
+
+ def test_parsed_body_without_as_option
+ post :render_json, body: { foo: "heyo" }
+ assert_equal({ "foo" => "heyo" }, response.parsed_body)
+ end
+
+ def test_parsed_body_with_as_option
+ post :render_json, body: { foo: "heyo" }, as: :json
+ assert_equal({ "foo" => "heyo" }, response.parsed_body)
+ end
end
class ResponseDefaultHeadersTest < ActionController::TestCase