Skip to content

Commit

Permalink
Merge pull request #5 from ubiregiinc/use-enqueue_to
Browse files Browse the repository at this point in the history
enqueue_at_with_queue内でenqueueでなくenqueue_toでエンキュー
  • Loading branch information
hsato23 authored Oct 23, 2024
2 parents 7b655e9 + 5f227e2 commit 7466565
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/resque_unit_without_mock/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions lib/resque_unit_without_mock/scheduler_assertions.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
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,
"#{klass} should have been queued in #{Resque.enqueue_ats(queue)} before #{expected_timestamp}"
)
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,
Expand Down
14 changes: 13 additions & 1 deletion test/resque_unit_without_mock/scheduler_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 7466565

Please sign in to comment.