модуль ActionDispatch::TestProcess::FixtureFile
Открытые методы экземпляров
# File actionpack/lib/action_dispatch/testing/test_process.rb, line 19
def fixture_file_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 Сокращение для Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.file_fixture_path, path), type).
post :change_avatar, params: { avatar: fixture_file_upload('david.png', 'image/png') }
По умолчанию, файлы фикстур находятся в test/fixtures/files.
Для загрузки бинарных файлов в Windows, передайте :binary в качестве последнего параметра. Это не повлияет на другие платформы:
post :change_avatar, params: { avatar: fixture_file_upload('david.png', 'image/png', :binary) }
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.