示例
Assert Rack::Test::UploadedFile defaults content_type to text/plain rather than inferring MIME types from file extensions and default_host defaults to example.org
sha256:a547a5386ea49e912d3240302a7c7194b1828e054d1785eb75c673f73f3711ef
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Assert Rack::Test::UploadedFile defaults content_type to text/plain rather than inferring MIME types from file extensions and default_host defaults to example.org HOW
- 包
- rack-test 2.2.0 rack 3.2.7
- 环境
- ruby
- 创建时间
- 2026-08-16T16:44:42Z
常见的想当然
Rack::Test::UploadedFile automatically infers the MIME content type from the file extension when the content_type argument is omitted.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- Rack::Test::UploadedFile.new with an image file path returns 'text/plain' for content_type rather than 'image/png' when the argument is omitted, because UploadedFile defaults content_type to 'text/plain' without inspecting the filename extension.
- assert posting an UploadedFile without an explicit content_type sends 'content-type: text/plain' in the multipart body and parses into params with :type 'text/plain'
- assert passing an explicit content_type argument overrides the default and preserves 'image/png' in both UploadedFile and multipart params
- assert UploadedFile wrapping a StringIO defaults content_type to 'text/plain' when content_type is left unset
- assert Rack::Test::Session defaults default_host to 'example.org' rather than 'localhost' when initialized without an explicit host
文件
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- src/upload_app.rb
- test/contract.rb
- test/fixtures/avatar.png
- test/fixtures/data.json
- test/fixtures/document.pdf
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- ruby 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · rubygems@1 · 2026-08-16 · ed25519:d91480838ac982c9