aboutsummaryrefslogtreecommitdiffstats
path: root/test/controllers/direct_uploads_controller_test.rb
diff options
context:
space:
mode:
authorDino Maric <dino.onex@gmail.com>2017-07-27 22:15:38 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2017-07-27 15:15:38 -0500
commite64e3f14fd255d91ac0aa7a272741df08da82701 (patch)
tree1fccbf0786ae9f981eae1b8cb736856b50479c23 /test/controllers/direct_uploads_controller_test.rb
parent293db49b7f5969d11d5599f97bd968dbe64c7f8b (diff)
downloadrails-e64e3f14fd255d91ac0aa7a272741df08da82701.tar.gz
rails-e64e3f14fd255d91ac0aa7a272741df08da82701.tar.bz2
rails-e64e3f14fd255d91ac0aa7a272741df08da82701.zip
Introduce the Dummy. (#70)
Diffstat (limited to 'test/controllers/direct_uploads_controller_test.rb')
-rw-r--r--test/controllers/direct_uploads_controller_test.rb36
1 files changed, 12 insertions, 24 deletions
diff --git a/test/controllers/direct_uploads_controller_test.rb b/test/controllers/direct_uploads_controller_test.rb
index 8c88befe6d..f15fcff314 100644
--- a/test/controllers/direct_uploads_controller_test.rb
+++ b/test/controllers/direct_uploads_controller_test.rb
@@ -1,14 +1,9 @@
require "test_helper"
require "database/setup"
-require "active_storage/direct_uploads_controller"
-
if SERVICE_CONFIGURATIONS[:s3]
- class ActiveStorage::S3DirectUploadsControllerTest < ActionController::TestCase
+ class ActiveStorage::S3DirectUploadsControllerTest < ActionDispatch::IntegrationTest
setup do
- @routes = Routes
- @controller = ActiveStorage::DirectUploadsController.new
-
@old_service = ActiveStorage::Blob.service
ActiveStorage::Blob.service = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS)
end
@@ -18,10 +13,10 @@ if SERVICE_CONFIGURATIONS[:s3]
end
test "creating new direct upload" do
- post :create, params: { blob: {
- filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
+ post rails_direct_uploads_url, params: { blob: {
+ filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
- JSON.parse(@response.body).tap do |details|
+ response.parsed_body.tap do |details|
assert_match(/#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws\.com/, details["upload_to_url"])
assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s
end
@@ -32,10 +27,8 @@ else
end
if SERVICE_CONFIGURATIONS[:gcs]
- class ActiveStorage::GCSDirectUploadsControllerTest < ActionController::TestCase
+ class ActiveStorage::GCSDirectUploadsControllerTest < ActionDispatch::IntegrationTest
setup do
- @routes = Routes
- @controller = ActiveStorage::DirectUploadsController.new
@config = SERVICE_CONFIGURATIONS[:gcs]
@old_service = ActiveStorage::Blob.service
@@ -47,10 +40,10 @@ if SERVICE_CONFIGURATIONS[:gcs]
end
test "creating new direct upload" do
- post :create, params: { blob: {
- filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
+ post rails_direct_uploads_url, params: { blob: {
+ filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
- JSON.parse(@response.body).tap do |details|
+ @response.parsed_body.tap do |details|
assert_match %r{storage\.googleapis\.com/#{@config[:bucket]}}, details["upload_to_url"]
assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s
end
@@ -60,17 +53,12 @@ else
puts "Skipping GCS Direct Upload tests because no GCS configuration was supplied"
end
-class ActiveStorage::DiskDirectUploadsControllerTest < ActionController::TestCase
- setup do
- @routes = Routes
- @controller = ActiveStorage::DirectUploadsController.new
- end
-
+class ActiveStorage::DiskDirectUploadsControllerTest < ActionDispatch::IntegrationTest
test "creating new direct upload" do
- post :create, params: { blob: {
- filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
+ post rails_direct_uploads_url, params: { blob: {
+ filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } }
- JSON.parse(@response.body).tap do |details|
+ @response.parsed_body.tap do |details|
assert_match /rails\/active_storage\/disk/, details["upload_to_url"]
assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s
end