rspec - Rspec - 测试 Carrierwave 上传器
问题描述
我需要为我的上传器测试我的自定义fog_public方法。
def fog_public
return false if mounted_as == :pdf_file
super
end
这个上传器正在多个地方使用,但我只需要在mounted_as == :pdf_file 时覆盖fog_public
这是我的规格文件:
require 'spec_helper'
describe PdfFileUploader do
include CarrierWave::Test::Matchers
let(:uploader) { described_class.new(mock_model(Report).as_null_object) }
before do
uploader.store!(File.open(Rails.root.join('spec', 'fixtures', 'files', 'testing_sample.pdf')))
end
it 'fog_public is false' do
expect(uploader.fog_public).to eq(false)
end
end
我的上传器在我的报告模型 中安装为:pdf_file 。由于我无法指定何时mount_as :pdf_file ,因此 fog_public 在规范中返回 true 。关于如何为特定模型指定mounted_as的任何想法?
解决方案
推荐阅读
- php - MongoDB / PHP / MapReduce / Reg Exp / Strings->Floats
- c# - c#如何检查一个字符串是否是数组中某个元素的子字符串,然后打印出来?
- php - lumen 5.7dusterio/lumen-passport 在 php artisan 迁移上失败
- java - 使用Java将10M记录从一个数据库迁移到另一个(在不同服务器上)的最佳策略是什么
- css - Bootstrap Grid 显示为文本
- javascript - 试图从两组字符之间提取数据
- sql-server - DATEPART missing months
- sql - Postgres 使用窗口函数计算差异
- javascript - 鼠标悬停在 iframe 上时父页面不滚动
- sql - PLSQL 语句执行但没有得到输出