aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2018-04-10 07:37:05 -0400
committerGitHub <noreply@github.com>2018-04-10 07:37:05 -0400
commit561aad0c186103232c094e38d4d3fe4ea4c083f3 (patch)
tree5673b305310972240d3f97799f9f7a7e6de187b8 /activestorage/test
parentc6ae623955909141fbea33e30742596423f61f78 (diff)
parentefb7dc65d9e38a824e1e8dbeb376b3fab5c7605b (diff)
downloadrails-561aad0c186103232c094e38d4d3fe4ea4c083f3.tar.gz
rails-561aad0c186103232c094e38d4d3fe4ea4c083f3.tar.bz2
rails-561aad0c186103232c094e38d4d3fe4ea4c083f3.zip
Merge pull request #32517 from javan/ast/no-root-in-json
Active Storage: Always exclude JSON root from direct_uploads#create response
Diffstat (limited to 'activestorage/test')
-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