Merge pull request #41067 from eugeneius/relative_file_fixture_path

Fix fixture_file_upload deprecation with relative file_fixture_path
This commit is contained in:
Eugene Kenny 2021-01-18 08:16:11 +00:00 committed by GitHub
commit 173e7ef16d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

@ -29,7 +29,7 @@ def fixture_file_upload(path, mime_type = nil, binary = false)
haven't set yet. Set `file_fixture_path` to discard this warning.
EOM
elsif path.exist?
non_deprecated_path = path.relative_path_from(Pathname(self.class.file_fixture_path))
non_deprecated_path = Pathname(File.absolute_path(path)).relative_path_from(Pathname(File.absolute_path(self.class.file_fixture_path)))
ActiveSupport::Deprecation.warn(<<~EOM)
Passing a path to `fixture_file_upload` relative to `fixture_path` is deprecated.
In Rails 6.2, the path needs to be relative to `file_fixture_path`.

@ -960,6 +960,19 @@ def test_fixture_file_upload_relative_to_fixture_path
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_ignores_fixture_path_given_full_path
TestCaseTest.stub :fixture_path, __dir__ do
uploaded_file = fixture_file_upload("#{FILES_DIR}/ruby_on_rails.jpg", "image/jpg")