DEV: make Jobs.enqueue tests less fragile
Previously we depended on non Sidekiq specific mocking which is not the official way of testing Sidekiq, this made these tests very fragile New testing is more robust and complete
This commit is contained in:
parent
df460b4abd
commit
824c3420e9
|
@ -11,13 +11,40 @@ describe Jobs do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'enqueues a job in sidekiq' do
|
it 'enqueues a job in sidekiq' do
|
||||||
Sidekiq::Client.expects(:enqueue).with(Jobs::ProcessPost, post_id: 1, current_site_id: 'default')
|
Sidekiq::Testing.fake! do
|
||||||
Jobs.enqueue(:process_post, post_id: 1)
|
jobs = Jobs::ProcessPost.jobs
|
||||||
|
|
||||||
|
jobs.clear
|
||||||
|
Jobs.enqueue(:process_post, post_id: 1)
|
||||||
|
expect(jobs.length).to eq(1)
|
||||||
|
job = jobs.first
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
"class" => "Jobs::ProcessPost",
|
||||||
|
"args" => [{ "post_id" => 1, "current_site_id" => "default" }],
|
||||||
|
"queue" => "default"
|
||||||
|
}
|
||||||
|
expect(job.slice("class", "args", "queue")).to eq(expected)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not pass current_site_id when 'all_sites' is present" do
|
it "does not pass current_site_id when 'all_sites' is present" do
|
||||||
Sidekiq::Client.expects(:enqueue).with(Jobs::ProcessPost, post_id: 1)
|
Sidekiq::Testing.fake! do
|
||||||
Jobs.enqueue(:process_post, post_id: 1, all_sites: true)
|
jobs = Jobs::ProcessPost.jobs
|
||||||
|
|
||||||
|
jobs.clear
|
||||||
|
Jobs.enqueue(:process_post, post_id: 1, all_sites: true)
|
||||||
|
|
||||||
|
expect(jobs.length).to eq(1)
|
||||||
|
job = jobs.first
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
"class" => "Jobs::ProcessPost",
|
||||||
|
"args" => [{ "post_id" => 1 }],
|
||||||
|
"queue" => "default"
|
||||||
|
}
|
||||||
|
expect(job.slice("class", "args", "queue")).to eq(expected)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't execute the job" do
|
it "doesn't execute the job" do
|
||||||
|
@ -27,10 +54,23 @@ describe Jobs do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should enqueue with the correct database id when the current_site_id option is given" do
|
it "should enqueue with the correct database id when the current_site_id option is given" do
|
||||||
Sidekiq::Client.expects(:enqueue).with do |arg1, arg2|
|
|
||||||
arg2[:current_site_id] == 'test_db' && arg2[:sync_exec].nil?
|
Sidekiq::Testing.fake! do
|
||||||
|
jobs = Jobs::ProcessPost.jobs
|
||||||
|
|
||||||
|
jobs.clear
|
||||||
|
Jobs.enqueue(:process_post, post_id: 1, current_site_id: 'test_db')
|
||||||
|
|
||||||
|
expect(jobs.length).to eq(1)
|
||||||
|
job = jobs.first
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
"class" => "Jobs::ProcessPost",
|
||||||
|
"args" => [{ "post_id" => 1, "current_site_id" => "test_db" }],
|
||||||
|
"queue" => "default"
|
||||||
|
}
|
||||||
|
expect(job.slice("class", "args", "queue")).to eq(expected)
|
||||||
end
|
end
|
||||||
Jobs.enqueue(:process_post, post_id: 1, current_site_id: 'test_db')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue