test/plugins/job/persistence_test.rb in rocketjob-2.1.3 vs test/plugins/job/persistence_test.rb in rocketjob-3.0.0.alpha
- old
+ new
@@ -4,27 +4,26 @@
module Job
# Unit Test for RocketJob::Job
class PersistenceTest < Minitest::Test
class PersistJob < RocketJob::Job
- rocket_job do |job|
- job.priority = 53
- end
+ self.priority = 53
+ field :data, type: Hash
def perform(hash)
hash
end
end
describe RocketJob::Plugins::Job::Persistence do
before do
RocketJob::Job.destroy_all
@description = 'Hello World'
- @arguments = [{key: 'value'}]
+ @data = {'key' => 'value'}
@job = PersistJob.new(
description: @description,
- arguments: [{key: 'value'}],
+ data: @data,
destroy_on_complete: false
)
end
after do
@@ -33,11 +32,11 @@
@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
+ assert_equal 'rocketjob_test', RocketJob::Job.collection.database.name
end
end
describe '.rocket_job' do
it 'sets defaults after initialize' do
@@ -45,18 +44,17 @@
end
end
describe '#reload' do
it 'handle hash' do
- assert_equal 'value', @job.arguments.first[:key]
+ assert_equal 'value', @job.data['key']
@job.worker_name = nil
@job.save!
@job.worker_name = '123'
@job.reload
- assert @job.arguments.first.is_a?(ActiveSupport::HashWithIndifferentAccess), @job.arguments.first.class.ai
- assert_equal 'value', @job.arguments.first['key']
- assert_equal 'value', @job.arguments.first[:key]
+ assert @job.data.is_a?(Hash), @job.data.class.ai
+ assert_equal 'value', @job.data['key']
assert_equal nil, @job.worker_name
end
end
describe '#save!' do
@@ -66,11 +64,11 @@
assert_nil @job.completed_at
assert @job.created_at
assert_equal @description, @job.description
assert_equal false, @job.destroy_on_complete
assert_nil @job.expires_at
- assert_equal @arguments, @job.arguments
+ assert_equal @data, @job.data
assert_equal 0, @job.percent_complete
assert_equal 53, @job.priority
assert_equal 0, @job.failure_count
assert_nil @job.run_at
assert_nil @job.started_at
@@ -79,11 +77,11 @@
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)
+ @job2 = PersistJob.create!(data: {key: 'value'})
+ @job3 = PersistJob.create!(data: {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]