diff --git a/lib/cloudinary/carrier_wave/process.rb b/lib/cloudinary/carrier_wave/process.rb index b1e12ad8..54e9aea0 100644 --- a/lib/cloudinary/carrier_wave/process.rb +++ b/lib/cloudinary/carrier_wave/process.rb @@ -154,8 +154,16 @@ def format format = Cloudinary::PreloadedFile.split_format(original_filename || "").last return format || "" if resource_type == "raw" format = requested_format || format || default_format - + format = format.to_s.downcase Cloudinary::FORMAT_ALIASES[format] || format end + + def store!(new_file=nil) + super + + column = model.send(:_mounter, mounted_as).send(:serialization_column) + identifier = model.send(:attribute, column) + retrieve_from_store!(identifier) unless identifier.nil? + end end diff --git a/spec/carriewave.rb b/spec/carriewave.rb new file mode 100644 index 00000000..318b6595 --- /dev/null +++ b/spec/carriewave.rb @@ -0,0 +1,34 @@ +require 'spec_helper' +require 'cloudinary' + +module CarrierWave + module Storage + class Abstract + def initialize(uploader) + @uploader = uploader + end + + attr_accessor :uploader + end + end + class SanitizedFile; end +end + +RSpec.describe Cloudinary::CarrierWave do + describe '#store!' do + let(:column) { 'example_field' } + let(:identifier) { 'identifier' } + let(:model) { double(:model, _mounter: mount) } + let(:mount) { double(:mount, serialization_column: column) } + let(:uploader) { spy(:uploader, model: model, mounted_as: :example).tap { |u| u.extend(Cloudinary::CarrierWave) } } + + subject { uploader.store! } + + it 'triggers `#retrieve_from_store!` after `#store!` executed to populate @file and @identifier' do + expect(model).to receive(:attribute).with(column).and_return(identifier) + expect(uploader).to receive(:retrieve_from_store!).with(identifier) + + subject + end + end +end