@@ -42,23 +42,33 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
42
42
end
43
43
44
44
test "create_and_upload extracts content type from data" do
45
- blob = create_file_blob content_type : "application/octet-stream"
45
+ blob = create_file_blob fixture : "racecar.jpg" , content_type : "application/octet-stream" , filename : "spoofed.txt "
46
46
assert_equal "image/jpeg" , blob . content_type
47
47
end
48
48
49
- test "create_and_upload extracts content type from filename" do
50
- blob = create_blob content_type : "application/octet-stream"
49
+ test "create_and_upload prefers given content type over filename" do
50
+ blob = create_blob content_type : "specific/type" , filename : "file.txt"
51
+ assert_equal "specific/type" , blob . content_type
52
+ end
53
+
54
+ test "create_and_upload prefers filename over binary content type" do
55
+ blob = create_blob content_type : "application/octet-stream" , filename : "file.txt"
51
56
assert_equal "text/plain" , blob . content_type
52
57
end
53
58
54
- test "create_and_upload extracts content_type from io when no content_type given and identify: false " do
55
- blob = create_blob content_type : nil , identify : false
59
+ test "create_and_upload extracts content type from filename " do
60
+ blob = create_blob content_type : nil , filename : "hello.txt"
56
61
assert_equal "text/plain" , blob . content_type
57
62
end
58
63
59
- test "create_and_upload uses content_type when identify: false" do
60
- blob = create_blob data : "Article,dates,analysis\n 1, 2, 3" , filename : "table.csv" , content_type : "text/csv" , identify : false
61
- assert_equal "text/csv" , blob . content_type
64
+ test "create_and_upload extracts content_type from io when missing and identify: false" do
65
+ blob = create_file_blob fixture : "racecar.jpg" , content_type : nil , filename : "unknown" , identify : false
66
+ assert_equal "image/jpeg" , blob . content_type
67
+ end
68
+
69
+ test "create_and_upload uses given content_type when identify: false" do
70
+ blob = create_file_blob fixture : "racecar.jpg" , content_type : "given/type" , filename : "unknown" , identify : false
71
+ assert_equal "given/type" , blob . content_type
62
72
end
63
73
64
74
test "create_and_upload generates a 28-character base36 key" do
0 commit comments