File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -53,8 +53,7 @@ def mutate
5353 ActiveRecord ::Base . transaction do
5454 topic . save_with_tags ( params )
5555 attach_files ( document_signed_ids )
56- # topic.persisted? means that we are updating existing topic and documents can be removed
57- shadow_delete_documents ( docs_to_delete ) if topic . persisted?
56+ shadow_delete_documents ( docs_to_delete )
5857 rename_files ( document_signed_ids )
5958 # document_signed_ids.any? means that some new documents were attached and we need to sync them
6059 sync_docs_for_topic_updates if document_signed_ids . any?
@@ -75,7 +74,7 @@ def attach_files(signed_ids)
7574 def rename_files ( signed_ids )
7675 return if signed_ids . blank?
7776 signed_ids . each do |signed_id |
78- document = topic . documents . find { |doc | doc . blob . signed_id == signed_id }
77+ document = topic . documents . find { |doc | doc . blob . signed_id == signed_id }
7978 next unless document
8079
8180 new_filename = topic . custom_file_name ( document )
Original file line number Diff line number Diff line change 2424 [
2525 ActiveStorage ::Blob . create_and_upload! (
2626 io : StringIO . new ( "dummy content" ) ,
27- filename : "dummy .pdf" ,
27+ filename : "rename_dummy .pdf" ,
2828 content_type : "application/pdf" ,
2929 ) . signed_id ,
3030 ]
4141 document_id : created_topic . documents . first . id ,
4242 action : "update" ,
4343 )
44+ expect ( created_topic . reload . documents . first . blob . filename . to_s ) . to eq ( "#{ created_topic . id } _prefix_2023_1_dummy.pdf" )
4445 end
4546 end
4647
8788 expect ( updated_topic ) . to be_persisted
8889 expect ( updated_topic . description ) . to eq ( "many topic details" )
8990 end
91+
92+ it "does not rename existing documents" do
93+ expect { subject . update } . not_to change { topic . reload . documents . first . blob . filename . to_s } . from ( "test_image.png" )
94+ end
9095 end
9196 end
9297
You can’t perform that action at this time.
0 commit comments