diff --git a/app/models/asset.rb b/app/models/asset.rb index fa582324..5f3b16ac 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -76,7 +76,7 @@ class Asset mount_uploader :file, AssetUploader - before_save :store_metadata, unless: :uploaded?, if: -> { changes.include?(:file) } + before_save :store_metadata, unless: :uploaded? after_save :schedule_virus_scan after_save :update_indirect_replacements_on_publish after_save :backpropagate_replacement diff --git a/spec/models/asset_spec.rb b/spec/models/asset_spec.rb index cf780db5..6605cbd9 100644 --- a/spec/models/asset_spec.rb +++ b/spec/models/asset_spec.rb @@ -1105,6 +1105,19 @@ expect(asset.save).to be_truthy end end + + context "when the file name is unchanged" do + let(:saved_asset) { FactoryBot.create(:asset) } + let(:md5_hexdigest) { saved_asset.md5_hexdigest } + let(:original_filename) { saved_asset.file.send(:original_filename) } + + it "updates the md5 hexdigest" do + asset = described_class.find(saved_asset.id) # find to clear memoization + asset.update!(file: load_fixture_file("lorem.txt", named: original_filename)) + + expect(asset.md5_hexdigest).not_to eq md5_hexdigest + end + end end describe "#replacement" do