ActiveStorage间歇性返回“找不到带有'id'的ActiveStorage :: Blob”

时间:2018-12-25 01:34:25

标签: ruby ruby-on-rails-5 sidekiq rails-activestorage

我有一个简单的控制器规范,该规范应检查在创建物料时是否排队处理新物料。

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. 如果问题出在哪里,我该如何调试文件上传?

谢谢!

1 个答案:

答案 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