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 "should work with 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 "should work with base64 file uploads" 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", "image.jpg") end end end