跳至内容 跳至搜索
方法
F

实例公共方法

file_fixture_upload(path, mime_type = nil, binary = false)

Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.file_fixture_path, path), type) 的快捷方式

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) }
# 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

fixture_file_upload(path, mime_type = nil, binary = false)