我有一个简单的控制器规范,该规范应检查在创建物料时是否排队处理新物料。
materials_controller_spec.rb(#create):
it 'queues the processing of the material' do
post :create, params: { material: valid_attributes }, session: valid_session
expect(ProcessMaterialJob).to(
have_been_enqueued.with(material_id: Material.last.id, video_filepath: Material.last.video_filepath)
)
end
孤立运行时很好,但是当我使用rspec .
运行整个套件时,出现以下错误:
ActiveJob::DeserializationError:
Error while trying to deserialize arguments: Couldn't find ActiveStorage::Blob with 'id'=418
# ./spec/controllers/materials_controller_spec.rb:81:in `block (4 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# ActiveRecord::RecordNotFound:
# Couldn't find ActiveStorage::Blob with 'id'=418
# ./spec/controllers/materials_controller_spec.rb:81:in `block (4 levels) in <top (required)>'
有两点我不能确信附件在下一页呈现之前已完全上传。我担心这可能意味着文件上传出现问题。我遵循了direct uploads上的指南,但是在上传很大的视频文件时仍然看不到进度指示。
我的问题是:
Couldn't find ActiveStorage::Blob
with 'id'=418
问题?谢谢!
答案 0 :(得分:0)
我以前将ActiveJob::Base.queue_adapter = :test
添加到了rails_helper.rb
中,所以它应该可以正常工作。但是,将该行添加到特定测试中似乎可以解决问题。
it 'queues the processing of the material' do
post :create, params: { material: valid_attributes }, session: valid_session
expect(ProcessMaterialJob).to(
have_been_enqueued.with(material_id: Material.last.id, video_filepath: Material.last.video_filepath)
)
end