test/plugins/job/persistence_test.rb in rocketjob-2.0.0 vs test/plugins/job/persistence_test.rb in rocketjob-2.1.1
- old
+ new
@@ -15,10 +15,11 @@
end
end
describe RocketJob::Plugins::Job::Persistence do
before do
+ RocketJob::Job.destroy_all
@description = 'Hello World'
@arguments = [{key: 'value'}]
@job = PersistJob.new(
description: @description,
arguments: [{key: 'value'}],
@@ -26,10 +27,12 @@
)
end
after do
@job.destroy if @job && !@job.new_record?
+ @job2.destroy if @job2 && !@job2.new_record?
+ @job3.destroy if @job3 && !@job3.new_record?
end
describe '.config' do
it 'support multiple databases' do
assert_equal 'test_rocketjob', RocketJob::Job.collection.db.name
@@ -70,9 +73,23 @@
assert_equal 53, @job.priority
assert_equal 0, @job.failure_count
assert_nil @job.run_at
assert_nil @job.started_at
assert_equal :queued, @job.state
+ end
+ end
+
+ describe '.counts_by_state' do
+ it 'returns states as symbols' do
+ @job.start!
+ @job2 = PersistJob.create!(arguments: [{key: 'value'}])
+ @job3 = PersistJob.create!(arguments: [{key: 'value'}], run_at: 1.day.from_now)
+ counts = RocketJob::Job.counts_by_state
+ assert_equal 4, counts.size, counts.ai
+ assert_equal 1, counts[:running]
+ assert_equal 2, counts[:queued]
+ assert_equal 1, counts[:queued_now]
+ assert_equal 1, counts[:scheduled]
end
end
end
end