方法
執行個體公用方法
連結file_fixture_upload(路徑, mime_類型 = nil, 二進位制 = false)
Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.file_f ixture_path, path), 類型)
的捷徑
post :change_avatar, params: { avatar: file_fixture_upload('david.png', 'image/png') }
預設固定檔案位置為 test/fixtures/files
。
如需上傳 Windows 上的二進位制檔案,請傳遞 :binary
作為最後一個參數。這樣不會影響其他平台
post :change_avatar, params: { avatar: file_fixture_upload('david.png', 'image/png', :binary) }
來源: 顯示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/testing/test_process.rb, line 23 def file_fixture_upload(path, mime_type = nil, binary = false) if self.class.file_fixture_path && !File.exist?(path) path = file_fixture(path) end Rack::Test::UploadedFile.new(path, mime_type, binary) end