tobi / delayed_job

Database backed asynchronous priority queue -- Extracted from Shopify
http://tobi.github.com/delayed_job
MIT License
2.15k stars 1.25k forks source link

No way to unit test send_later effectively #21

Open noctivityinc opened 14 years ago

noctivityinc commented 14 years ago

I am trying to unit test DJ with some emails that are being set to send_later. While I can check the database for the record, it seems like it would make more sense if I could:

1 - Check that DJ has it 2 - Simulate a run 3 - Check to make sure it ran as expected.

Any thoughts?

ctaintor commented 14 years ago

Yup. You should be able to do the following in a unit test:

  1. Verify there are no delayed jobs already in the db: assert_equal 0, Delayed::Job.count
  2. Make a call that will result in the job being enqueued
  3. Verify that DJ has it assert_equal 1, Delayed::Job.count
  4. Simulate a run Delayed::Worker.new.work_off
  5. Check that it ran as expected assert_equal 0, Delayed::Job.count and then any assertions that you need to do to check that DJ actually worked.