Rails test triggers Sidekiq warning

Viewed 850

I have the following method in a Sidekiq worker:

  def self.schedule_edits(course:, editing_user:, enrollment_results:)
    puts editing_user.id
    perform_async(course.id, editing_user.id, enrollment_results)
  end

I have a controller test that, when it calls this code throws the following warning:

WARN: Job arguments to MassEnrollmentWorker do not serialize to JSON safely. This will raise an error...

I have read up on the warning HERE and I'm guessing that enrollment_results is the offending argument. However, when I run the test and output enrollment_results, here is what I see:

{"FirstUser"=>{:success=>"User added to course."}, "SecondUser"=>{:success=>"User added to course."}, "NotARealUserOnWikipedia"=>{:failure=>"Not an existing user."}

This appears to be a valid hash, so what is the issue?

3 Answers

For posterity; I fixed this by changing way the hash was build from:

{"FirstUser"=>{:success=>"User added to course."}, "SecondUser"=>{:success=>"User added to course."}, "NotARealUserOnWikipedia"=>{:failure=>"Not an existing user."}

to...

{"FirstUser"=>{"success"=>"User added to course."}, "SecondUser"=>{"success"=>"User added to course."}, "NotARealUserOnWikipedia"=>{"failure"=>"Not an existing user."}

On my case I just needed to change the format of my hashmap to the string rocket => style.

From:

 Sidekiq::Client.push('class' => 'RecordOrderJob', 'args' => { foo: 'bar' })

to:

Sidekiq::Client.push('class' => 'RecordOrderJob', 'args' => { 'foo' => 'bar' })

just avoid symbols in the hash.

Related