mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Update fixture_file_upload
documentation to reflect recent changes. (#39340)
* Update `fixture_file_upload` documentation to reflect recent changes. [ci skip] * Friendlier deprecation message for `fixture_file_upload`. Suggested change now can be copied and pasted into the code without modification.
This commit is contained in:
parent
4774fa0d26
commit
1ab0e6b6d8
2 changed files with 8 additions and 6 deletions
|
@ -6,14 +6,16 @@ require "action_dispatch/middleware/flash"
|
|||
module ActionDispatch
|
||||
module TestProcess
|
||||
module FixtureFile
|
||||
# Shortcut for <tt>Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.fixture_path, path), type)</tt>:
|
||||
# Shortcut for <tt>Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.file_fixture_path, path), type)</tt>:
|
||||
#
|
||||
# post :change_avatar, params: { avatar: fixture_file_upload('files/spongebob.png', 'image/png') }
|
||||
# post :change_avatar, params: { avatar: fixture_file_upload('spongebob.png', 'image/png') }
|
||||
#
|
||||
# Default fixture files location is <tt>test/fixtures/files</tt>.
|
||||
#
|
||||
# To upload binary files on Windows, pass <tt>:binary</tt> as the last parameter.
|
||||
# This will not affect other platforms:
|
||||
#
|
||||
# post :change_avatar, params: { avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary) }
|
||||
# post :change_avatar, params: { avatar: fixture_file_upload('spongebob.png', 'image/png', :binary) }
|
||||
def fixture_file_upload(path, mime_type = nil, binary = false)
|
||||
if self.class.respond_to?(:fixture_path) && self.class.fixture_path &&
|
||||
!File.exist?(path)
|
||||
|
@ -33,7 +35,7 @@ module ActionDispatch
|
|||
In Rails 6.2, the path needs to be relative to `file_fixture_path`.
|
||||
|
||||
Please modify the call from
|
||||
`fixture_file_upload(#{original_path})` to `fixture_file_upload(#{non_deprecated_path})`.
|
||||
`fixture_file_upload("#{original_path}")` to `fixture_file_upload("#{non_deprecated_path}")`.
|
||||
EOM
|
||||
else
|
||||
path = file_fixture(original_path)
|
||||
|
|
|
@ -874,7 +874,7 @@ XML
|
|||
|
||||
def test_fixture_path_is_accessed_from_self_instead_of_active_support_test_case
|
||||
TestCaseTest.stub :fixture_path, File.expand_path("../fixtures", __dir__) do
|
||||
expected = "`fixture_file_upload(multipart/ruby_on_rails.jpg)` to `fixture_file_upload(ruby_on_rails.jpg)`"
|
||||
expected = "`fixture_file_upload(\"multipart/ruby_on_rails.jpg\")` to `fixture_file_upload(\"ruby_on_rails.jpg\")`"
|
||||
|
||||
assert_deprecated(expected) do
|
||||
uploaded_file = fixture_file_upload("multipart/ruby_on_rails.jpg", "image/png")
|
||||
|
@ -940,7 +940,7 @@ XML
|
|||
|
||||
def test_fixture_file_upload_relative_to_fixture_path
|
||||
TestCaseTest.stub :fixture_path, File.expand_path("../fixtures", __dir__) do
|
||||
expected = "`fixture_file_upload(multipart/ruby_on_rails.jpg)` to `fixture_file_upload(ruby_on_rails.jpg)`"
|
||||
expected = "`fixture_file_upload(\"multipart/ruby_on_rails.jpg\")` to `fixture_file_upload(\"ruby_on_rails.jpg\")`"
|
||||
|
||||
assert_deprecated(expected) do
|
||||
uploaded_file = fixture_file_upload("multipart/ruby_on_rails.jpg", "image/jpg")
|
||||
|
|
Loading…
Reference in a new issue