summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-15 03:09:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-15 03:09:11 +0000
commitb71a496c7a3e109f7c85ad7ac453e6f7bf7cda45 (patch)
tree0a76fc00ef860bd369dcaa3f136ee36275eb47f5 /spec/support
parentc2041156b8b3063d6cf29b324416e8469e588923 (diff)
downloadgitlab-ce-b71a496c7a3e109f7c85ad7ac453e6f7bf7cda45.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/helpers/workhorse_helpers.rb36
-rw-r--r--spec/support/rails/test_case_patch.rb53
2 files changed, 80 insertions, 9 deletions
diff --git a/spec/support/helpers/workhorse_helpers.rb b/spec/support/helpers/workhorse_helpers.rb
index de232da3c8c..53b36b3dd45 100644
--- a/spec/support/helpers/workhorse_helpers.rb
+++ b/spec/support/helpers/workhorse_helpers.rb
@@ -33,22 +33,36 @@ module WorkhorseHelpers
# workhorse_finalize will transform file_key inside params as if it was the finalize call of an inline object storage upload.
# note that based on the content of the params it can simulate a disc acceleration or an object storage upload
def workhorse_finalize(url, method: :post, file_key:, params:, headers: {}, send_rewritten_field: false)
- workhorse_request_with_file(method, url,
- file_key: file_key,
- params: params,
- extra_headers: headers,
- send_rewritten_field: send_rewritten_field
+ workhorse_finalize_with_multiple_files(url, method: method, file_keys: file_key, params: params, headers: headers, send_rewritten_field: send_rewritten_field)
+ end
+
+ def workhorse_finalize_with_multiple_files(url, method: :post, file_keys:, params:, headers: {}, send_rewritten_field: false)
+ workhorse_request_with_multiple_files(method, url,
+ file_keys: file_keys,
+ params: params,
+ extra_headers: headers,
+ send_rewritten_field: send_rewritten_field
)
end
def workhorse_request_with_file(method, url, file_key:, params:, env: {}, extra_headers: {}, send_rewritten_field:)
+ workhorse_request_with_multiple_files(method, url, file_keys: file_key, params: params, env: env, extra_headers: extra_headers, send_rewritten_field: send_rewritten_field)
+ end
+
+ def workhorse_request_with_multiple_files(method, url, file_keys:, params:, env: {}, extra_headers: {}, send_rewritten_field:)
workhorse_params = params.dup
- file = workhorse_params.delete(file_key)
- workhorse_params = workhorse_disk_accelerated_file_params(file_key, file).merge(workhorse_params)
+ file_keys = Array(file_keys)
+ rewritten_fields = {}
+
+ file_keys.each do |key|
+ file = workhorse_params.delete(key)
+ rewritten_fields[key] = file.path if file
+ workhorse_params = workhorse_disk_accelerated_file_params(key, file).merge(workhorse_params)
+ end
headers = if send_rewritten_field
- workhorse_rewritten_fields_header(file_key => file.path)
+ workhorse_rewritten_fields_header(rewritten_fields)
else
{}
end
@@ -75,7 +89,11 @@ module WorkhorseHelpers
"#{key}.name" => file.original_filename,
"#{key}.size" => file.size
}.tap do |params|
- params["#{key}.path"] = file.path if file.path
+ if file.path
+ params["#{key}.path"] = file.path
+ params["#{key}.sha256"] = Digest::SHA256.file(file.path).hexdigest
+ end
+
params["#{key}.remote_id"] = file.remote_id if file.respond_to?(:remote_id) && file.remote_id.present?
end
end
diff --git a/spec/support/rails/test_case_patch.rb b/spec/support/rails/test_case_patch.rb
new file mode 100644
index 00000000000..161e1ef2a4c
--- /dev/null
+++ b/spec/support/rails/test_case_patch.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+#
+# This file pulls in the changes in https://github.com/rails/rails/pull/38063
+# to fix controller specs updated with the latest Rack versions.
+#
+# This file should be removed after that change ships. It is not
+# present in Rails 6.0.2.2.
+module ActionController
+ class TestRequest < ActionDispatch::TestRequest #:nodoc:
+ def self.new_session
+ TestSessionPatched.new
+ end
+ end
+
+ # Methods #destroy and #load! are overridden to avoid calling methods on the
+ # @store object, which does not exist for the TestSession class.
+ class TestSessionPatched < Rack::Session::Abstract::PersistedSecure::SecureSessionHash #:nodoc:
+ DEFAULT_OPTIONS = Rack::Session::Abstract::Persisted::DEFAULT_OPTIONS
+
+ def initialize(session = {})
+ super(nil, nil)
+ @id = Rack::Session::SessionId.new(SecureRandom.hex(16))
+ @data = stringify_keys(session)
+ @loaded = true
+ end
+
+ def exists?
+ true
+ end
+
+ def keys
+ @data.keys
+ end
+
+ def values
+ @data.values
+ end
+
+ def destroy
+ clear
+ end
+
+ def fetch(key, *args, &block)
+ @data.fetch(key.to_s, *args, &block)
+ end
+
+ private
+
+ def load!
+ @id
+ end
+ end
+end