carrierwave-base64 icon indicating copy to clipboard operation
carrierwave-base64 copied to clipboard

Have to reload AR model when saving base64 photos.

Open bramski opened this issue 6 years ago • 5 comments

Seeing a bit of odd behavior. Gemfile.lock:

carrierwave (1.1.0)
      activemodel (>= 4.0.0)
      activesupport (>= 4.0.0)
      mime-types (>= 1.16)
    carrierwave-base64 (2.5.3)
      carrierwave (>= 0.8.0)
      mime-types (~> 3.0)

Model looks like:

 mount_base64_uploader :original_photo, PatronPhotoUploader

In a spec I have the following:

describe "#original_photo=" do
    let(:new_photo) { build(:patron_photo, original_photo: original_photo) }
    context "base64 encoded" do
      let(:original_photo) { valid_base64_image }
      it "accepts base64-encoded images" do
        expect(new_photo).to be_valid
        expect { new_photo.save! }.not_to raise_error
        expect(new_photo.original_photo).to be_present
      end
    end
  end

However, the check for presence fails.

1) PatronPhoto#original_photo= base64 encoded accepts base64-encoded images
     Failure/Error: expect(new_photo.original_photo).to be_present
       expected `#<PatronPhotoUploader:0x007f8ef4a441f8 @model=#<PatronPhoto id: 3, original_photo: "ukpu42doyhyfyov8y...Storage:0x007f8ef3ddf098 @uploader=#<PatronPhotoUploader:0x007f8ef4a441f8 ...>>, @transformation={}>.present?` to return true, got false

If I reload the active record before checking for presence it succeeds.

bramski avatar Aug 22 '17 18:08 bramski

@bramski did you sort out a workaround for this? We do a bunch of client params processing in a method far away from having access to the model itself, so we don't have an easy way to reload the model unless we reload every model.

bbugh avatar Oct 17 '18 19:10 bbugh

@bramski @bbugh Can you share some details on the versions of carrierwave and rails gems you use?

I've tried reproducing the bug without any success: ab8fdf12

y9v avatar Oct 22 '18 09:10 y9v

We're on Rails 5.2, Carrierwave 1.2.3. I'm using Cloudinary as the CDN which has some code that extends Carrierwave, so it's possible that the extended code is breaking it. @bramski were you using Cloudinary as well?

bbugh avatar Oct 22 '18 23:10 bbugh

I'm closing this, until I can reproduce this bug. Feel free to re-open it if it is still actual

y9v avatar Nov 01 '18 08:11 y9v

@y9v I can confirm this happens with carrierwave, cloudinary & carrierwave-base64 on rails 4.2.11.1 as well. Need to reload for the presence check to work.

yourtallness avatar Mar 31 '19 20:03 yourtallness