From f4e58cb0206a180b1fe84cc6a3a59bbbb6d3142a Mon Sep 17 00:00:00 2001 From: Yohta Kimura Date: Wed, 13 Sep 2023 22:07:41 +0900 Subject: [PATCH] add failing test cases for https://github.com/carrierwaveuploader/carrierwave/issues/2702 --- spec/orm/activerecord_spec.rb | 48 +++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/spec/orm/activerecord_spec.rb b/spec/orm/activerecord_spec.rb index cd74f7305..67a444145 100644 --- a/spec/orm/activerecord_spec.rb +++ b/spec/orm/activerecord_spec.rb @@ -635,18 +635,17 @@ def filename end end - describe 'with overriddent filename' do - - describe '#save' do - - before do - @uploader.class_eval do - def filename - model.name + File.extname(super) - end + describe 'with overridden filename' do + before do + @uploader.class_eval do + def filename + model.name + File.extname(super) end - allow(@event).to receive(:name).and_return('jonas') end + allow(@event).to receive(:name).and_return('jonas') + end + + describe '#save' do it "should copy the file to the upload directory when a file has been assigned" do @event.image = stub_file('test.jpeg') @@ -664,6 +663,33 @@ def filename end + describe '#changes' do + it "should be generated" do + @event.image = stub_file('test.jpeg') + expect(@event.changes).to eq({'image' => [nil, 'test.jpeg']}) + end + + it "shouldn't be generated when the attribute value is unchanged" do + @event.image = stub_file('test.jpeg') + @event.save! + @event.image = @event[:image] + + expect(@event.changes).to be_blank + expect(@event).not_to be_changed + @event.remote_image_url = "" + expect(@event).not_to be_changed + end + + it "shouldn't be generated after second save" do + @event.image = stub_file('old.jpeg') + @event.save! + @event.image = stub_file('new.jpeg') + @event.save! + + expect(@event.changes).to be_blank + expect(@event).not_to be_changed + end + end end describe 'with validates_presence_of' do @@ -1552,7 +1578,7 @@ def filename end end - describe 'with overriddent filename' do + describe 'with overridden filename' do describe '#save' do