diff --git a/lib/resque_unit_without_mock/scheduler.rb b/lib/resque_unit_without_mock/scheduler.rb index 459f212..b2076c4 100644 --- a/lib/resque_unit_without_mock/scheduler.rb +++ b/lib/resque_unit_without_mock/scheduler.rb @@ -17,7 +17,7 @@ def enqueue_at_with_queue(queue, timestamp, klass, *args) @@enqueue_ats ||= {} @@enqueue_ats[queue] ||= [] @@enqueue_ats[queue] << { timestamp: timestamp, klass: klass, args: args } - Resque.enqueue(klass, *args) + Resque.enqueue_to(queue, klass, *args) end def enqueue_ats(queue) diff --git a/lib/resque_unit_without_mock/scheduler_assertions.rb b/lib/resque_unit_without_mock/scheduler_assertions.rb index 170cc8e..e6a4e12 100644 --- a/lib/resque_unit_without_mock/scheduler_assertions.rb +++ b/lib/resque_unit_without_mock/scheduler_assertions.rb @@ -1,6 +1,13 @@ module ResqueUnitWithoutMock::SchedulerAssertions def assert_queued_at(expected_timestamp, klass) - queue = Resque.queue_for(klass) + assert_queued_at_with_queue(Resque.queue_for(klass), expected_timestamp, klass) + end + + def assert_not_queued_at(expected_timestamp, klass) + assert_not_queued_at_with_queue(Resque.queue_for(klass), expected_timestamp, klass) + end + + def assert_queued_at_with_queue(queue, expected_timestamp, klass) result = Resque.enqueue_ats(queue).detect { |hash| hash[:timestamp] <= expected_timestamp && hash[:klass] == klass } assert( result, @@ -8,8 +15,7 @@ def assert_queued_at(expected_timestamp, klass) ) end - def assert_not_queued_at(expected_timestamp, klass) - queue = Resque.queue_for(klass) + def assert_not_queued_at_with_queue(queue, expected_timestamp, klass) result = Resque.enqueue_ats(queue).detect { |hash| hash[:timestamp] <= expected_timestamp && hash[:klass] == klass } assert( !result, diff --git a/test/resque_unit_without_mock/scheduler_assertions_test.rb b/test/resque_unit_without_mock/scheduler_assertions_test.rb index 45c5840..0795e56 100644 --- a/test/resque_unit_without_mock/scheduler_assertions_test.rb +++ b/test/resque_unit_without_mock/scheduler_assertions_test.rb @@ -30,7 +30,7 @@ def test_assert_queued_at assert_queued_at(Time.new(2011,11,11,0,0,3), PrintJob) end - def test_assert_queued_at_with_queue + def test_assert_queued_at_with_class_defined_queue # |=> queued!! # | |\\|\\\\\\\\ # 1 2 3 @@ -41,4 +41,16 @@ def test_assert_queued_at_with_queue assert_queued_at(Time.new(2011,11,11,0,0,2), PrintJob) assert_queued_at(Time.new(2011,11,11,0,0,3), PrintJob) end + + def test_assert_queued_at_with_queue + # |=> queued!! + # | |\\|\\\\\\\\ + # 1 2 3 + assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob) + assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,3), PrintJob) + Resque.enqueue_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob) + assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,1), PrintJob) + assert_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob) + assert_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,3), PrintJob) + end end