Shrine

Mime-type is null for tempfile

trying to test validations in a spec

    Tempfile.create(["sam' p+le", ".mp4"], binmode: true) do |tempfile|
      tempfile.write File.open(test_file, "r", binmode: true).read
      model.attachment = tempfile
      expect(model.valid?).to eq(true)
    end

the validation fails because the mime_type is nil in the attachment_data json. If I run the file command on the tempfile in cache it returns the correct values.

Is it because we are using the block form for Tempfile.create?

Got it. Needed a tempfile.rewind before the assignment, now it’s working as expected