Spec-Zone.ru › Ruby on Rails 5.0

модуль ActionDispatch::TestProcess::FixtureFile

Публичные методы экземпляра

fixture_file_upload(path, mime_type = nil, binary = false) Показать исходный код
# File actionpack/lib/action_dispatch/testing/test_process.rb, line 15
def fixture_file_upload(path, mime_type = nil, binary = false)
  if self.class.respond_to?(:fixture_path) && self.class.fixture_path &&
      !File.exist?(path)
    path = File.join(self.class.fixture_path, path)
  end
  Rack::Test::UploadedFile.new(path, mime_type, binary)
end

Сокращение для Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.fixture_path, path), type):

post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png')

Чтобы загружать двоичные файлы в Windows, передайте :binary в качестве последнего параметра. Это не повлияет на другие платформы:

post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary)

© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API