Skip to content

Commit 6b2a9f1

Browse files
authored
Merge pull request rails#50967 from zzak/asto/fix-controller-tests
Fix Active Storage test configurations for CI
2 parents 0602e1e + 4873347 commit 6b2a9f1

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

activestorage/Rakefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ Rake::TestTask.new do |t|
1313
end
1414

1515
if ENV["encrypted_0fb9444d0374_key"] && ENV["encrypted_0fb9444d0374_iv"]
16-
file "test/service/configurations.yml" do
17-
system "openssl aes-256-cbc -K $encrypted_0fb9444d0374_key -iv $encrypted_0fb9444d0374_iv -in test/service/configurations.yml.enc -out test/service/configurations.yml -d"
16+
config_file = "test/service/configurations.yml"
17+
file config_file do
18+
puts "Generating #{config_file} for Active Storage tests..."
19+
system "openssl aes-256-cbc -K $encrypted_0fb9444d0374_key -iv $encrypted_0fb9444d0374_iv -in #{config_file}.enc -out #{config_file} -d"
1820
end
1921

20-
task test: "test/service/configurations.yml"
22+
task test: config_file
2123
end
2224

2325
task :package

activestorage/test/controllers/direct_uploads_controller_test.rb

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class ActiveStorage::S3DirectUploadsControllerTest < ActionDispatch::Integration
1717
test "creating new direct upload" do
1818
checksum = OpenSSL::Digest::MD5.base64digest("Hello")
1919
metadata = {
20-
"foo": "bar",
21-
"my_key_1": "my_value_1",
22-
"my_key_2": "my_value_2",
23-
"platform": "my_platform",
24-
"library_ID": "12345",
25-
"custom": {
26-
"my_key_3": "my_value_3"
20+
"foo" => "bar",
21+
"my_key_1" => "my_value_1",
22+
"my_key_2" => "my_value_2",
23+
"platform" => "my_platform",
24+
"library_ID" => "12345",
25+
"custom" => {
26+
"my_key_3" => "my_value_3"
2727
}
2828
}
2929

@@ -35,7 +35,7 @@ class ActiveStorage::S3DirectUploadsControllerTest < ActionDispatch::Integration
3535
assert_equal "hello.txt", details["filename"]
3636
assert_equal 6, details["byte_size"]
3737
assert_equal checksum, details["checksum"]
38-
assert_equal metadata, details["metadata"].deep_transform_keys(&:to_sym)
38+
assert_equal metadata, details["metadata"]
3939
assert_equal "text/plain", details["content_type"]
4040
assert_match SERVICE_CONFIGURATIONS[:s3][:bucket], details["direct_upload"]["url"]
4141
assert_match(/s3(-[-a-z0-9]+)?\.(\S+)?amazonaws\.com/, details["direct_upload"]["url"])
@@ -63,25 +63,25 @@ class ActiveStorage::GCSDirectUploadsControllerTest < ActionDispatch::Integratio
6363
test "creating new direct upload" do
6464
checksum = OpenSSL::Digest::MD5.base64digest("Hello")
6565
metadata = {
66-
"foo": "bar",
67-
"my_key_1": "my_value_1",
68-
"my_key_2": "my_value_2",
69-
"platform": "my_platform",
70-
"library_ID": "12345",
71-
"custom": {
72-
"my_key_3": "my_value_3"
66+
"foo" => "bar",
67+
"my_key_1" => "my_value_1",
68+
"my_key_2" => "my_value_2",
69+
"platform" => "my_platform",
70+
"library_ID" => "12345",
71+
"custom" => {
72+
"my_key_3" => "my_value_3"
7373
}
7474
}
7575

7676
post rails_direct_uploads_url, params: { blob: {
7777
filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain", metadata: metadata } }
7878

79-
@response.parsed_body.tap do |details|
79+
response.parsed_body.tap do |details|
8080
assert_equal ActiveStorage::Blob.find(details["id"]), ActiveStorage::Blob.find_signed!(details["signed_id"])
8181
assert_equal "hello.txt", details["filename"]
8282
assert_equal 6, details["byte_size"]
8383
assert_equal checksum, details["checksum"]
84-
assert_equal metadata, details["metadata"].deep_transform_keys(&:to_sym)
84+
assert_equal metadata, details["metadata"]
8585
assert_equal "text/plain", details["content_type"]
8686
assert_match %r{storage\.googleapis\.com/#{@config[:bucket]}}, details["direct_upload"]["url"]
8787
assert_equal({ "Content-MD5" => checksum, "Content-Disposition" => "inline; filename=\"hello.txt\"; filename*=UTF-8''hello.txt", "x-goog-meta-my_key_3" => "my_value_3" }, details["direct_upload"]["headers"])
@@ -108,22 +108,22 @@ class ActiveStorage::AzureStorageDirectUploadsControllerTest < ActionDispatch::I
108108
test "creating new direct upload" do
109109
checksum = OpenSSL::Digest::MD5.base64digest("Hello")
110110
metadata = {
111-
"foo": "bar",
112-
"my_key_1": "my_value_1",
113-
"my_key_2": "my_value_2",
114-
"platform": "my_platform",
115-
"library_ID": "12345"
111+
"foo" => "bar",
112+
"my_key_1" => "my_value_1",
113+
"my_key_2" => "my_value_2",
114+
"platform" => "my_platform",
115+
"library_ID" => "12345"
116116
}
117117

118118
post rails_direct_uploads_url, params: { blob: {
119119
filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain", metadata: metadata } }
120120

121-
@response.parsed_body.tap do |details|
121+
response.parsed_body.tap do |details|
122122
assert_equal ActiveStorage::Blob.find(details["id"]), ActiveStorage::Blob.find_signed!(details["signed_id"])
123123
assert_equal "hello.txt", details["filename"]
124124
assert_equal 6, details["byte_size"]
125125
assert_equal checksum, details["checksum"]
126-
assert_equal metadata, details["metadata"].deep_transform_keys(&:to_sym)
126+
assert_equal metadata, details["metadata"]
127127
assert_equal "text/plain", details["content_type"]
128128
assert_match %r{#{@config[:storage_account_name]}\.blob\.core\.windows\.net/#{@config[:container]}}, details["direct_upload"]["url"]
129129
assert_equal({ "Content-Type" => "text/plain", "Content-MD5" => checksum, "x-ms-blob-content-disposition" => "inline; filename=\"hello.txt\"; filename*=UTF-8''hello.txt", "x-ms-blob-type" => "BlockBlob" }, details["direct_upload"]["headers"])
@@ -148,7 +148,7 @@ class ActiveStorage::DiskDirectUploadsControllerTest < ActionDispatch::Integrati
148148
post rails_direct_uploads_url, params: { blob: {
149149
filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain", metadata: metadata } }
150150

151-
@response.parsed_body.tap do |details|
151+
response.parsed_body.tap do |details|
152152
assert_equal ActiveStorage::Blob.find(details["id"]), ActiveStorage::Blob.find_signed!(details["signed_id"])
153153
assert_equal "hello.txt", details["filename"]
154154
assert_equal 6, details["byte_size"]
@@ -163,19 +163,19 @@ class ActiveStorage::DiskDirectUploadsControllerTest < ActionDispatch::Integrati
163163
test "creating new direct upload does not include root in json" do
164164
checksum = OpenSSL::Digest::MD5.base64digest("Hello")
165165
metadata = {
166-
"foo": "bar",
167-
"my_key_1": "my_value_1",
168-
"my_key_2": "my_value_2",
169-
"platform": "my_platform",
170-
"library_ID": "12345"
166+
"foo" => "bar",
167+
"my_key_1" => "my_value_1",
168+
"my_key_2" => "my_value_2",
169+
"platform" => "my_platform",
170+
"library_ID" => "12345"
171171
}
172172

173173
set_include_root_in_json(true) do
174174
post rails_direct_uploads_url, params: { blob: {
175175
filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain", metadata: metadata } }
176176
end
177177

178-
@response.parsed_body.tap do |details|
178+
response.parsed_body.tap do |details|
179179
assert_nil details["blob"]
180180
assert_not_nil details["id"]
181181
end

activestorage/test/dummy/config/environments/test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
config.active_storage.service = :local
3838

3939
SERVICE_CONFIGURATIONS = begin
40-
ActiveSupport::ConfigurationFile.parse(File.expand_path("service/configurations.yml", __dir__)).deep_symbolize_keys
40+
config_file = Rails.root.join("../service/configurations.yml")
41+
ActiveSupport::ConfigurationFile.parse(config_file, symbolize_names: true)
4142
rescue Errno::ENOENT
42-
puts "Missing service configuration file in test/service/configurations.yml"
43+
puts "Missing service configuration file in #{config_file}"
4344
{}
4445
end
4546
# Azure service tests are currently failing on the main branch.

0 commit comments

Comments
 (0)