From d0407497ec83a8455d9ee85bb9cc34ef2449f0cb Mon Sep 17 00:00:00 2001 From: dixpac Date: Sat, 22 Jul 2017 15:41:32 +0200 Subject: Move all controller tests to controller/ dir --- test/controllers/direct_uploads_controller_test.rb | 66 ++++++++++++++++++++++ test/controllers/disk_controller_test.rb | 25 ++++++++ test/direct_uploads_controller_test.rb | 66 ---------------------- test/disk_controller_test.rb | 25 -------- 4 files changed, 91 insertions(+), 91 deletions(-) create mode 100644 test/controllers/direct_uploads_controller_test.rb create mode 100644 test/controllers/disk_controller_test.rb delete mode 100644 test/direct_uploads_controller_test.rb delete mode 100644 test/disk_controller_test.rb (limited to 'test') diff --git a/test/controllers/direct_uploads_controller_test.rb b/test/controllers/direct_uploads_controller_test.rb new file mode 100644 index 0000000000..8aa61f53cb --- /dev/null +++ b/test/controllers/direct_uploads_controller_test.rb @@ -0,0 +1,66 @@ +require "test_helper" +require "database/setup" + +require "action_controller" +require "action_controller/test_case" + +require "active_storage/direct_uploads_controller" + +if SERVICE_CONFIGURATIONS[:s3] + class ActiveStorage::S3DirectUploadsControllerTest < ActionController::TestCase + setup do + @blob = create_blob + @routes = Routes + @controller = ActiveStorage::DirectUploadsController.new + + @old_service = ActiveStorage::Blob.service + ActiveStorage::Blob.service = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS) + end + + teardown do + ActiveStorage::Blob.service = @old_service + 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" } } + + details = JSON.parse(@response.body) + + assert_match /#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws\.com/, details["url"] + assert_equal "hello.txt", GlobalID::Locator.locate_signed(details["sgid"]).filename.to_s + end + end +else + puts "Skipping S3 Direct Upload tests because no S3 configuration was supplied" +end + +if SERVICE_CONFIGURATIONS[:gcs] + class ActiveStorage::GCSDirectUploadsControllerTest < ActionController::TestCase + setup do + @blob = create_blob + @routes = Routes + @controller = ActiveStorage::DirectUploadsController.new + @config = SERVICE_CONFIGURATIONS[:gcs] + + @old_service = ActiveStorage::Blob.service + ActiveStorage::Blob.service = ActiveStorage::Service.configure(:gcs, SERVICE_CONFIGURATIONS) + end + + teardown do + ActiveStorage::Blob.service = @old_service + 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" } } + + details = JSON.parse(@response.body) + + assert_match %r{storage\.googleapis\.com/#{@config[:bucket]}}, details["url"] + assert_equal "hello.txt", GlobalID::Locator.locate_signed(details["sgid"]).filename.to_s + end + end +else + puts "Skipping GCS Direct Upload tests because no GCS configuration was supplied" +end diff --git a/test/controllers/disk_controller_test.rb b/test/controllers/disk_controller_test.rb new file mode 100644 index 0000000000..834ad1bfd9 --- /dev/null +++ b/test/controllers/disk_controller_test.rb @@ -0,0 +1,25 @@ +require "test_helper" +require "database/setup" + +require "active_storage/disk_controller" +require "active_storage/verified_key_with_expiration" + +class ActiveStorage::DiskControllerTest < ActionController::TestCase + setup do + @blob = create_blob + @routes = Routes + @controller = ActiveStorage::DiskController.new + end + + test "showing blob inline" do + get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage::VerifiedKeyWithExpiration.encode(@blob.key, expires_in: 5.minutes) } + assert_equal "inline; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"] + assert_equal "text/plain", @response.headers["Content-Type"] + end + + test "sending blob as attachment" do + get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage::VerifiedKeyWithExpiration.encode(@blob.key, expires_in: 5.minutes), disposition: :attachment } + assert_equal "attachment; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"] + assert_equal "text/plain", @response.headers["Content-Type"] + end +end diff --git a/test/direct_uploads_controller_test.rb b/test/direct_uploads_controller_test.rb deleted file mode 100644 index 8aa61f53cb..0000000000 --- a/test/direct_uploads_controller_test.rb +++ /dev/null @@ -1,66 +0,0 @@ -require "test_helper" -require "database/setup" - -require "action_controller" -require "action_controller/test_case" - -require "active_storage/direct_uploads_controller" - -if SERVICE_CONFIGURATIONS[:s3] - class ActiveStorage::S3DirectUploadsControllerTest < ActionController::TestCase - setup do - @blob = create_blob - @routes = Routes - @controller = ActiveStorage::DirectUploadsController.new - - @old_service = ActiveStorage::Blob.service - ActiveStorage::Blob.service = ActiveStorage::Service.configure(:s3, SERVICE_CONFIGURATIONS) - end - - teardown do - ActiveStorage::Blob.service = @old_service - 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" } } - - details = JSON.parse(@response.body) - - assert_match /#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws\.com/, details["url"] - assert_equal "hello.txt", GlobalID::Locator.locate_signed(details["sgid"]).filename.to_s - end - end -else - puts "Skipping S3 Direct Upload tests because no S3 configuration was supplied" -end - -if SERVICE_CONFIGURATIONS[:gcs] - class ActiveStorage::GCSDirectUploadsControllerTest < ActionController::TestCase - setup do - @blob = create_blob - @routes = Routes - @controller = ActiveStorage::DirectUploadsController.new - @config = SERVICE_CONFIGURATIONS[:gcs] - - @old_service = ActiveStorage::Blob.service - ActiveStorage::Blob.service = ActiveStorage::Service.configure(:gcs, SERVICE_CONFIGURATIONS) - end - - teardown do - ActiveStorage::Blob.service = @old_service - 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" } } - - details = JSON.parse(@response.body) - - assert_match %r{storage\.googleapis\.com/#{@config[:bucket]}}, details["url"] - assert_equal "hello.txt", GlobalID::Locator.locate_signed(details["sgid"]).filename.to_s - end - end -else - puts "Skipping GCS Direct Upload tests because no GCS configuration was supplied" -end diff --git a/test/disk_controller_test.rb b/test/disk_controller_test.rb deleted file mode 100644 index 834ad1bfd9..0000000000 --- a/test/disk_controller_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require "test_helper" -require "database/setup" - -require "active_storage/disk_controller" -require "active_storage/verified_key_with_expiration" - -class ActiveStorage::DiskControllerTest < ActionController::TestCase - setup do - @blob = create_blob - @routes = Routes - @controller = ActiveStorage::DiskController.new - end - - test "showing blob inline" do - get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage::VerifiedKeyWithExpiration.encode(@blob.key, expires_in: 5.minutes) } - assert_equal "inline; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"] - assert_equal "text/plain", @response.headers["Content-Type"] - end - - test "sending blob as attachment" do - get :show, params: { filename: @blob.filename, encoded_key: ActiveStorage::VerifiedKeyWithExpiration.encode(@blob.key, expires_in: 5.minutes), disposition: :attachment } - assert_equal "attachment; filename=\"#{@blob.filename}\"", @response.headers["Content-Disposition"] - assert_equal "text/plain", @response.headers["Content-Type"] - end -end -- cgit v1.2.3