Skip to content

Commit 77bb3af

Browse files
authored
Small changes in TopicsMutator (#367)
2 parents 72c55b1 + 315b26e commit 77bb3af

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

app/services/topics/mutator.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff 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)

spec/services/topics/mutator_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
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
]
@@ -41,6 +41,7 @@
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

@@ -87,6 +88,10 @@
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

0 commit comments

Comments
 (0)