Skip to content

Commit

Permalink
Merge pull request #41067 from eugeneius/relative_file_fixture_path
Browse files Browse the repository at this point in the history
Fix fixture_file_upload deprecation with relative file_fixture_path
  • Loading branch information
eugeneius committed Jan 18, 2021
2 parents e889cc5 + a7b548a commit 173e7ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/testing/test_process.rb
Expand Up @@ -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`.
Expand Down
13 changes: 13 additions & 0 deletions actionpack/test/controller/test_case_test.rb
Expand Up @@ -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")
Expand Down

0 comments on commit 173e7ef

Please sign in to comment.