mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove deprecated support to passing a path to fixture_file_upload
relative to fixture_path
This commit is contained in:
parent
35645ed17f
commit
1f4a541421
4 changed files with 7 additions and 90 deletions
|
@ -1,3 +1,7 @@
|
|||
* Remove deprecated support to passing a path to `fixture_file_upload` relative to `fixture_path`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated `ActionDispatch::SystemTestCase#host!`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
|
|
@ -17,33 +17,7 @@ module ActionDispatch
|
|||
#
|
||||
# post :change_avatar, params: { avatar: fixture_file_upload('david.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)
|
||||
original_path = path
|
||||
path = Pathname.new(self.class.fixture_path).join(path)
|
||||
|
||||
if !self.class.file_fixture_path
|
||||
ActiveSupport::Deprecation.warn(<<~EOM)
|
||||
Passing a path to `fixture_file_upload` relative to `fixture_path` is deprecated.
|
||||
In Rails 7.0, the path needs to be relative to `file_fixture_path` which you
|
||||
haven't set yet. Set `file_fixture_path` to discard this warning.
|
||||
EOM
|
||||
elsif path.exist?
|
||||
non_deprecated_path = Pathname(File.absolute_path(path)).relative_path_from(Pathname(File.absolute_path(self.class.file_fixture_path)))
|
||||
|
||||
if Pathname(original_path) != non_deprecated_path
|
||||
ActiveSupport::Deprecation.warn(<<~EOM)
|
||||
Passing a path to `fixture_file_upload` relative to `fixture_path` is deprecated.
|
||||
In Rails 7.0, 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}")`.
|
||||
EOM
|
||||
end
|
||||
else
|
||||
path = file_fixture(original_path)
|
||||
end
|
||||
elsif self.class.file_fixture_path && !File.exist?(path)
|
||||
if self.class.file_fixture_path && !File.exist?(path)
|
||||
path = file_fixture(path)
|
||||
end
|
||||
|
||||
|
|
|
@ -883,17 +883,6 @@ XML
|
|||
assert_equal new_content_type, file.content_type
|
||||
end
|
||||
|
||||
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\")`"
|
||||
|
||||
assert_deprecated(expected) do
|
||||
uploaded_file = fixture_file_upload("multipart/ruby_on_rails.jpg", "image/png")
|
||||
assert_equal File.open("#{FILES_DIR}/ruby_on_rails.jpg", READ_PLAIN).read, uploaded_file.read
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_test_uploaded_file_with_binary
|
||||
filename = "ruby_on_rails.jpg"
|
||||
path = "#{FILES_DIR}/#{filename}"
|
||||
|
@ -931,58 +920,6 @@ XML
|
|||
assert_equal "45142", @response.body
|
||||
end
|
||||
|
||||
def test_fixture_file_upload_output_deprecation_when_file_fixture_path_is_not_set
|
||||
TestCaseTest.stub :fixture_path, File.expand_path("../fixtures", __dir__) do
|
||||
TestCaseTest.stub :file_fixture_path, nil do
|
||||
assert_deprecated(/In Rails 7.0, the path needs to be relative to `file_fixture_path`/) do
|
||||
fixture_file_upload("multipart/ruby_on_rails.jpg", "image/jpeg")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_fixture_file_upload_does_not_output_deprecation_when_file_fixture_path_is_set
|
||||
TestCaseTest.stub :fixture_path, File.expand_path("../fixtures", __dir__) do
|
||||
assert_not_deprecated do
|
||||
fixture_file_upload("ruby_on_rails.jpg", "image/jpeg")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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\")`"
|
||||
|
||||
assert_deprecated(expected) do
|
||||
uploaded_file = fixture_file_upload("multipart/ruby_on_rails.jpg", "image/jpeg")
|
||||
assert_equal File.open("#{FILES_DIR}/ruby_on_rails.jpg", READ_PLAIN).read, uploaded_file.read
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_fixture_file_upload_relative_to_fixture_path_with_relative_file_fixture_path
|
||||
TestCaseTest.stub :fixture_path, File.expand_path("../fixtures", __dir__) do
|
||||
TestCaseTest.stub :file_fixture_path, "test/fixtures/multipart" do
|
||||
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")
|
||||
assert_equal File.open("#{FILES_DIR}/ruby_on_rails.jpg", READ_PLAIN).read, uploaded_file.read
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_fixture_file_upload_fixture_path_same_as_file_fixture_path
|
||||
TestCaseTest.stub :fixture_path, File.expand_path("../fixtures/multipart", __dir__) do
|
||||
TestCaseTest.stub :file_fixture_path, File.expand_path("../fixtures/multipart", __dir__) do
|
||||
assert_not_deprecated do
|
||||
fixture_file_upload("ruby_on_rails.jpg", "image/jpg")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_fixture_file_upload_ignores_fixture_path_given_full_path
|
||||
TestCaseTest.stub :fixture_path, __dir__ do
|
||||
uploaded_file = fixture_file_upload("#{FILES_DIR}/ruby_on_rails.jpg", "image/jpeg")
|
||||
|
|
|
@ -58,6 +58,8 @@ Please refer to the [Changelog][action-pack] for detailed changes.
|
|||
|
||||
* Remove deprecated `ActionDispatch::SystemTestCase#host!`.
|
||||
|
||||
* Remove deprecated support to passing a path to `fixture_file_upload` relative to `fixture_path`.
|
||||
|
||||
### Deprecations
|
||||
|
||||
### Notable changes
|
||||
|
|
Loading…
Reference in a new issue