Sha256: f0e0c726c77772936b1ccdd5269966c6140ad935b9b4fa6b289cdddb99a9c78a
Contents?: true
Size: 1.71 KB
Versions: 2
Compression:
Stored size: 1.71 KB
Contents
RSpec.describe Carrierwave::Base64::Base64StringIO do %w(application/vnd.openxmlformats-officedocument.wordprocessingml.document image/jpeg application/pdf audio/mpeg).each do |content_type| context "correct #{content_type} data" do let(:data) do "data:#{content_type};base64,/9j/4AAQSkZJRgABAQEASABKdhH//2Q==" end let(:file_extension) do MIME::Types[content_type].last.preferred_extension end subject { described_class.new data, 'file' } it 'determines the file format from the Data URI content type' do expect(subject.file_extension).to eql(file_extension) end it 'should respond to :original_filename' do expect(subject.original_filename).to eql("file.#{file_extension}") end it 'calls a function that returns the file_name' do method = ->(u) { u.username } base64_string_io = described_class.new data, method.curry[User.new] expect(base64_string_io.file_name).to eql('batman') end it 'accepts a string as the file name as well' do model = described_class.new data, 'string-file-name' expect(model.file_name).to eql('string-file-name') end end end context 'invalid image data' do it 'raises an ArgumentError if Data URI content type is missing' do expect do described_class.new('/9j/4AAQSkZJRgABAQEASABIAADKdhH//2Q==', 'file') end.to raise_error(Carrierwave::Base64::Base64StringIO::ArgumentError) end it 'raises ArgumentError if base64 data eql (null)' do expect do described_class.new('data:image/jpeg;base64,(null)', 'file') end.to raise_error(Carrierwave::Base64::Base64StringIO::ArgumentError) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
carrierwave-base64-2.5.0 | spec/base64_string_io_spec.rb |
carrierwave-base64-2.4.0 | spec/base64_string_io_spec.rb |