File tree Expand file tree Collapse file tree 4 files changed +27
-1
lines changed
lib/active_storage/attached Expand file tree Collapse file tree 4 files changed +27
-1
lines changed Original file line number Diff line number Diff line change
1
+ * Deprecate ` config.active_storage.replace_on_assign_to_many ` . Future versions of Rails
2
+ will behave the same way as when the config is set to ` true ` .
3
+
4
+ * Santiago Bartesaghi*
5
+
1
6
* Remove deprecated methods: ` build_after_upload ` , ` create_after_upload! ` in favor of ` create_and_upload! ` ,
2
7
and ` service_url ` in favor of ` url ` .
3
8
Original file line number Diff line number Diff line change @@ -145,6 +145,12 @@ def #{name}=(attachables)
145
145
ActiveStorage::Attached::Changes::CreateMany.new("#{ name } ", self, attachables)
146
146
end
147
147
else
148
+ ActiveSupport::Deprecation.warn \
149
+ "config.active_storage.replace_on_assign_to_many is deprecated and will be removed in Rails 7.1. " \
150
+ "Make sure that your code works well with config.active_storage.replace_on_assign_to_many set to true before upgrading. " \
151
+ "To append new attachables to the Active Storage association, prefer using `attach`. " \
152
+ "Using association setter would result in purging the existing attached attachments and replacing them with new ones."
153
+
148
154
if Array(attachables).any?
149
155
attachment_changes["#{ name } "] =
150
156
ActiveStorage::Attached::Changes::CreateMany.new("#{ name } ", self, #{ name } .blobs + attachables)
Original file line number Diff line number Diff line change @@ -777,6 +777,21 @@ def highlights
777
777
end
778
778
end
779
779
780
+ test "deprecation warning when replace_on_assign_to_many is false" do
781
+ append_on_assign do
782
+ message = <<-MSG . squish
783
+ DEPRECATION WARNING: config.active_storage.replace_on_assign_to_many is deprecated and will be removed in Rails 7.1.
784
+ Make sure that your code works well with config.active_storage.replace_on_assign_to_many set to true before upgrading.
785
+ To append new attachables to the Active Storage association, prefer using `attach`.
786
+ Using association setter would result in purging the existing attached attachments and replacing them with new ones.
787
+ MSG
788
+
789
+ assert_deprecated ( message ) do
790
+ @user . update! highlights : [ create_blob ( filename : "whenever.jpg" ) ]
791
+ end
792
+ end
793
+ end
794
+
780
795
private
781
796
def append_on_assign
782
797
ActiveStorage . replace_on_assign_to_many , previous = false , ActiveStorage . replace_on_assign_to_many
Original file line number Diff line number Diff line change @@ -697,7 +697,7 @@ user.highlights.first.filename # => "funky.jpg"
697
697
user.highlights.second.filename # => "town.jpg"
698
698
```
699
699
700
- Existing applications can opt in to this new behavior by setting ` config.active_storage.replace_on_assign_to_many ` to ` true ` . The old behavior will be deprecated in Rails 6.1 and removed in a subsequent release .
700
+ Existing applications can opt in to this new behavior by setting ` config.active_storage.replace_on_assign_to_many ` to ` true ` . The old behavior will be deprecated in Rails 7.0 and removed in Rails 7.1 .
701
701
702
702
Upgrading from Rails 5.1 to Rails 5.2
703
703
-------------------------------------
You can’t perform that action at this time.
0 commit comments