No way to unit test send_later effectively #21

Open
noctivityinc opened this Issue Feb 18, 2010 · 1 comment

Projects

None yet

2 participants

@noctivityinc

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment