Sha256: 060d81dc628641b3457efc499258b430836ab49c9d50c9b4ba65119aef352610

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require "spec_helper"

require "carrierwave/base64/orm/activerecord"

RSpec.describe Carrierwave::Base64::ActiveRecord do
  describe ".mount_base64_uploader" do
    let(:uploader) { Class.new CarrierWave::Uploader::Base }

    subject do
      Post.mount_base64_uploader(:image, uploader)
      Post.new
    end

    it "mounts the uploader on the image field" do
      expect(subject.image).to be_an_instance_of(uploader)
    end

    it "handles normal file uploads" do
      sham_rack_app = ShamRack.at('www.example.com').stub
      sham_rack_app.register_resource("/test.jpg", file_path("fixtures", "test.jpg"), "images/jpg")
      subject[:image] = "test.jpg"
      subject.save!
      subject.reload
      expect(subject.image.current_path).to eq file_path("../uploads", "test.jpg")
    end

    it "handles data-urls" do
      subject.image = File.read(file_path("fixtures", "base64_image.fixture")).strip
      subject.save!
      subject.reload
      expect(subject.image.current_path).to eq file_path("../uploads", "file.jpg")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
carrierwave-base64-1.6 spec/orm/activerecord_spec.rb
carrierwave-base64-1.5 spec/orm/activerecord_spec.rb
carrierwave-base64-1.4 spec/orm/activerecord_spec.rb