ActiveStorage 间歇性返回 "Couldn't find ActiveStorage::Blob with 'id'"

ActiveStorage intermittently returning "Couldn't find ActiveStorage::Blob with 'id'"

我有一个简单的控制器规范,它应该检查在创建项目时排队的新 Material 处理。

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 上的指南进行操作,但在上传视频文件时仍然没有看到进度指示器,这些文件非常大。

我的问题是:

  1. 是什么导致了奇怪的 Couldn't find ActiveStorage::Blob with 'id'=418 问题?
  2. 如果这是问题所在,我该如何调试文件上传?

提前致谢!

我之前将 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