aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/controllers/direct_uploads_controller_test.rb
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2018-04-10 06:36:47 -0400
committerJavan Makhmali <javan@javan.us>2018-04-10 06:36:47 -0400
commitefb7dc65d9e38a824e1e8dbeb376b3fab5c7605b (patch)
tree5673b305310972240d3f97799f9f7a7e6de187b8 /activestorage/test/controllers/direct_uploads_controller_test.rb
parentc6ae623955909141fbea33e30742596423f61f78 (diff)
downloadrails-efb7dc65d9e38a824e1e8dbeb376b3fab5c7605b.tar.gz
rails-efb7dc65d9e38a824e1e8dbeb376b3fab5c7605b.tar.bz2
rails-efb7dc65d9e38a824e1e8dbeb376b3fab5c7605b.zip
Always exclude JSON root from direct_uploads#create response
The JavaScript component expects a bare response. Fixes #32365
Diffstat (limited to 'activestorage/test/controllers/direct_uploads_controller_test.rb')
-rw-r--r--activestorage/test/controllers/direct_uploads_controller_test.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activestorage/test/controllers/direct_uploads_controller_test.rb b/activestorage/test/controllers/direct_uploads_controller_test.rb
index 88d85e12ab..1b16da17d9 100644
--- a/activestorage/test/controllers/direct_uploads_controller_test.rb
+++ b/activestorage/test/controllers/direct_uploads_controller_test.rb
@@ -121,4 +121,27 @@ class ActiveStorage::DiskDirectUploadsControllerTest < ActionDispatch::Integrati
assert_equal({ "Content-Type" => "text/plain" }, details["direct_upload"]["headers"])
end
end
+
+ test "creating new direct upload does not include root in json" do
+ checksum = Digest::MD5.base64digest("Hello")
+
+ set_include_root_in_json(true) do
+ post rails_direct_uploads_url, params: { blob: {
+ filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain" } }
+ end
+
+ @response.parsed_body.tap do |details|
+ assert_nil details["blob"]
+ assert_not_nil details["id"]
+ end
+ end
+
+ private
+ def set_include_root_in_json(value)
+ original = ActiveRecord::Base.include_root_in_json
+ ActiveRecord::Base.include_root_in_json = value
+ yield
+ ensure
+ ActiveRecord::Base.include_root_in_json = original
+ end
end