Skip to content

Commit db28662

Browse files
committed
Don't show deprecation warning for equal paths
Before, if a user set `file_fixture_path` to the same path as `fixture_path`, this would have resulted in a deprecation warning such as: "Please modify the call from `fixture_file_upload('rails.jpg')` to `fixture_file_upload('rails.jpg')"
1 parent fa1a4b6 commit db28662

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

actionpack/lib/action_dispatch/testing/test_process.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ def fixture_file_upload(path, mime_type = nil, binary = false)
3030
EOM
3131
elsif path.exist?
3232
non_deprecated_path = Pathname(File.absolute_path(path)).relative_path_from(Pathname(File.absolute_path(self.class.file_fixture_path)))
33-
ActiveSupport::Deprecation.warn(<<~EOM)
34-
Passing a path to `fixture_file_upload` relative to `fixture_path` is deprecated.
35-
In Rails 7.0, the path needs to be relative to `file_fixture_path`.
3633

37-
Please modify the call from
38-
`fixture_file_upload("#{original_path}")` to `fixture_file_upload("#{non_deprecated_path}")`.
39-
EOM
34+
if Pathname(original_path) != non_deprecated_path
35+
ActiveSupport::Deprecation.warn(<<~EOM)
36+
Passing a path to `fixture_file_upload` relative to `fixture_path` is deprecated.
37+
In Rails 7.0, the path needs to be relative to `file_fixture_path`.
38+
39+
Please modify the call from
40+
`fixture_file_upload("#{original_path}")` to `fixture_file_upload("#{non_deprecated_path}")`.
41+
EOM
42+
end
4043
else
4144
path = file_fixture(original_path)
4245
end

actionpack/test/controller/test_case_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,16 @@ def test_fixture_file_upload_relative_to_fixture_path_with_relative_file_fixture
973973
end
974974
end
975975

976+
def test_fixture_file_upload_fixture_path_same_as_file_fixture_path
977+
TestCaseTest.stub :fixture_path, File.expand_path("../fixtures/multipart", __dir__) do
978+
TestCaseTest.stub :file_fixture_path, File.expand_path("../fixtures/multipart", __dir__) do
979+
assert_not_deprecated do
980+
fixture_file_upload("ruby_on_rails.jpg", "image/jpg")
981+
end
982+
end
983+
end
984+
end
985+
976986
def test_fixture_file_upload_ignores_fixture_path_given_full_path
977987
TestCaseTest.stub :fixture_path, __dir__ do
978988
uploaded_file = fixture_file_upload("#{FILES_DIR}/ruby_on_rails.jpg", "image/jpeg")

0 commit comments

Comments
 (0)