Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions activestorage/app/models/active_storage/blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,15 @@ def service
def content_type=(value)
unless ActiveStorage.silence_invalid_content_types_warning
if INVALID_VARIABLE_CONTENT_TYPES_DEPRECATED_IN_RAILS_7.include?(value)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
ActiveStorage.deprecator.warn(<<-MSG.squish)
#{value} is not a valid content type, it should not be used when creating a blob, and support for it will be removed in Rails 7.1.
If you want to keep supporting this content type past Rails 7.1, add it to `config.active_storage.variable_content_types`.
Dismiss this warning by setting `config.active_storage.silence_invalid_content_types_warning = true`.
MSG
end

if INVALID_VARIABLE_CONTENT_TYPES_TO_SERVE_AS_BINARY_DEPRECATED_IN_RAILS_7.include?(value)
ActiveSupport::Deprecation.warn(<<-MSG.squish)
ActiveStorage.deprecator.warn(<<-MSG.squish)
#{value} is not a valid content type, it should not be used when creating a blob, and support for it will be removed in Rails 7.1.
If you want to keep supporting this content type past Rails 7.1, add it to `config.active_storage.content_types_to_serve_as_binary`.
Dismiss this warning by setting `config.active_storage.silence_invalid_content_types_warning = true`.
Expand Down
4 changes: 2 additions & 2 deletions activestorage/app/models/active_storage/current.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ class ActiveStorage::Current < ActiveSupport::CurrentAttributes # :nodoc:
attribute :url_options

def host=(host)
ActiveSupport::Deprecation.warn("ActiveStorage::Current.host= is deprecated, instead use ActiveStorage::Current.url_options=")
ActiveStorage.deprecator.warn("ActiveStorage::Current.host= is deprecated, instead use ActiveStorage::Current.url_options=")
self.url_options = { host: host }
end

def host
ActiveSupport::Deprecation.warn("ActiveStorage::Current.host is deprecated, instead use ActiveStorage::Current.url_options")
ActiveStorage.deprecator.warn("ActiveStorage::Current.host is deprecated, instead use ActiveStorage::Current.url_options")
self.url_options&.dig(:host)
end
end
1 change: 1 addition & 0 deletions activestorage/lib/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require "active_support/core_ext/numeric/time"

require "active_storage/version"
require "active_storage/deprecator"
require "active_storage/errors"

require "marcel"
Expand Down
4 changes: 2 additions & 2 deletions activestorage/lib/active_storage/attached/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def #{name}=(attachables)
ActiveStorage::Attached::Changes::CreateMany.new("#{name}", self, attachables, pending_uploads: pending_uploads)
end
else
ActiveSupport::Deprecation.warn \
ActiveStorage.deprecator.warn \
"config.active_storage.replace_on_assign_to_many is deprecated and will be removed in Rails 7.1. " \
"Make sure that your code works well with config.active_storage.replace_on_assign_to_many set to true before upgrading. " \
"To append new attachables to the Active Storage association, prefer using `attach`. " \
Expand Down Expand Up @@ -179,7 +179,7 @@ def purge_later
def deprecate(action)
reflection_name = proxy_association.reflection.name
attached_name = reflection_name.to_s.partition("_").first
ActiveSupport::Deprecation.warn(<<-MSG.squish)
ActiveStorage.deprecator.warn(<<-MSG.squish)
Calling `#{action}` from `#{reflection_name}` is deprecated and will be removed in Rails 7.1.
To migrate to Rails 7.1's behavior call `#{action}` from `#{attached_name}` instead: `#{attached_name}.#{action}`.
MSG
Expand Down
7 changes: 7 additions & 0 deletions activestorage/lib/active_storage/deprecator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module ActiveStorage
def self.deprecator # :nodoc:
@deprecator ||= ActiveSupport::Deprecation.new
end
end
4 changes: 4 additions & 0 deletions activestorage/lib/active_storage/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class Engine < Rails::Engine # :nodoc:

config.eager_load_namespaces << ActiveStorage

initializer "active_storage.deprecator" do |app|
app.deprecators[:active_storage] = ActiveStorage.deprecator
end

initializer "active_storage.configs" do
config.after_initialize do |app|
ActiveStorage.logger = app.config.active_storage.logger || Rails.logger
Expand Down
14 changes: 7 additions & 7 deletions activestorage/test/models/attached/many_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase

test "attaching new blobs within a transaction with append_on_assign config uploads all the files" do
append_on_assign do
assert_deprecated do
assert_deprecated(ActiveStorage.deprecator) do
ActiveRecord::Base.transaction do
@user.highlights.attach fixture_file_upload("racecar.jpg")
@user.highlights.attach fixture_file_upload("video.mp4")
Expand All @@ -223,7 +223,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase

test "attaching new blobs within a transaction with append_on_assign config create the exact amount of records" do
append_on_assign do
assert_deprecated do
assert_deprecated(ActiveStorage.deprecator) do
assert_difference -> { ActiveStorage::Blob.count }, +2 do
ActiveRecord::Base.transaction do
@user.highlights.attach fixture_file_upload("racecar.jpg")
Expand Down Expand Up @@ -414,7 +414,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase

test "updating an existing record with attachments when appending on assign" do
append_on_assign do
assert_deprecated do
assert_deprecated(ActiveStorage.deprecator) do
@user.highlights.attach create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg")

assert_difference -> { @user.reload.highlights.count }, +2 do
Expand Down Expand Up @@ -605,7 +605,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
Calling `purge` from `highlights_attachments` is deprecated and will be removed in Rails 7.1.
To migrate to Rails 7.1's behavior call `purge` from `highlights` instead: `highlights.purge`.
MSG
assert_deprecated(message) do
assert_deprecated(message, ActiveStorage.deprecator) do
assert_changes -> { @user.updated_at } do
@user.highlights_attachments.purge
end
Expand Down Expand Up @@ -700,7 +700,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
Calling `purge_later` from `highlights_attachments` is deprecated and will be removed in Rails 7.1.
To migrate to Rails 7.1's behavior call `purge_later` from `highlights` instead: `highlights.purge_later`.
MSG
assert_deprecated(message) do
assert_deprecated(message, ActiveStorage.deprecator) do
perform_enqueued_jobs do
assert_changes -> { @user.updated_at } do
@user.highlights_attachments.purge_later
Expand Down Expand Up @@ -963,7 +963,7 @@ def highlights

test "successfully attaches new blobs and destroys attachments marked for destruction via nested attributes" do
append_on_assign do
assert_deprecated do
assert_deprecated(ActiveStorage.deprecator) do
town_blob = create_blob(filename: "town.jpg")
@user.highlights.attach(town_blob)
@user.reload
Expand Down Expand Up @@ -991,7 +991,7 @@ def highlights
Using association setter would result in purging the existing attached attachments and replacing them with new ones.
MSG

assert_deprecated(message) do
assert_deprecated(message, ActiveStorage.deprecator) do
@user.update! highlights: [create_blob(filename: "whenever.jpg")]
end
end
Expand Down
12 changes: 6 additions & 6 deletions activestorage/test/models/blob_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
end

test "warning if blob is created with invalid mime type" do
assert_deprecated do
assert_deprecated(ActiveStorage.deprecator) do
create_blob(filename: "funky.jpg", content_type: "image/jpg")
end

assert_not_deprecated do
assert_not_deprecated(ActiveStorage.deprecator) do
create_blob(filename: "funky.jpg", content_type: "image/jpeg")
end

assert_not_deprecated do
assert_not_deprecated(ActiveStorage.deprecator) do
create_file_blob(filename: "colors.bmp", content_type: "image/bmp")
end
end
Expand All @@ -366,15 +366,15 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
warning_was = ActiveStorage.silence_invalid_content_types_warning
ActiveStorage.silence_invalid_content_types_warning = true

assert_not_deprecated do
assert_not_deprecated(ActiveStorage.deprecator) do
create_blob(filename: "funky.jpg", content_type: "image/jpg")
end

assert_not_deprecated do
assert_not_deprecated(ActiveStorage.deprecator) do
create_blob(filename: "funky.jpg", content_type: "image/jpeg")
end

assert_not_deprecated do
assert_not_deprecated(ActiveStorage.deprecator) do
create_file_blob(filename: "colors.bmp", content_type: "image/bmp")
end

Expand Down
2 changes: 1 addition & 1 deletion activestorage/test/models/variant_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
blob = create_file_blob(filename: "racecar.jpg")

# image/jpg is not recognised by mini_mime (image/jpeg is correct)
assert_deprecated do
assert_deprecated(ActiveStorage.deprecator) do
blob.update(content_type: "image/jpg")
end

Expand Down
2 changes: 1 addition & 1 deletion activestorage/test/service/disk_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase

test "URL generation keeps working with ActiveStorage::Current.host set" do
ActiveStorage::Current.url_options = nil
assert_deprecated { ActiveStorage::Current.host = "https://example.com" }
assert_deprecated(ActiveStorage.deprecator) { ActiveStorage::Current.host = "https://example.com" }

original_url_options = Rails.application.routes.default_url_options.dup
Rails.application.routes.default_url_options.merge!(protocol: "http", host: "test.example.com", port: 3001)
Expand Down
1 change: 1 addition & 0 deletions railties/test/application/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,7 @@ def new(app); self; end
assert_equal ActionMailer.deprecator, Rails.application.deprecators[:action_mailer]
assert_equal ActionView.deprecator, Rails.application.deprecators[:action_view]
assert_equal ActiveRecord.deprecator, Rails.application.deprecators[:active_record]
assert_equal ActiveStorage.deprecator, Rails.application.deprecators[:active_storage]
assert_equal ActiveSupport.deprecator, Rails.application.deprecators[:active_support]
end

Expand Down