Skip to content

Commit

Permalink
Add specs for retry_all and delete_all using job_class or job_excepti…
Browse files Browse the repository at this point in the history
…on specified
  • Loading branch information
Alejandro Perea committed Nov 23, 2018
1 parent f32a597 commit 7d9de03
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion test/functional/failures_controller_test.rb
Expand Up @@ -25,10 +25,52 @@ class FailuresControllerTest < ActionController::TestCase

describe "DELETE /failures/destroy_all" do
it "deletes all failures" do
Resque::Failure.expects(:clear).with('failed')
Resque::Failure.stubs(:count).returns(2)
Resque::Failure.expects(:remove).with(0)
Resque::Failure.expects(:remove).with(1)
visit(:destroy_all, {}, :method => :delete)
assert_redirected_to failures_path
end

it 'deletes all failures with the job class specified' do
Resque::Failure.stubs(:count).returns(2)
Resque::Failure.stubs(:all).with(0).returns(
{
'payload' => { 'args' => ['job_class' => 'JobClass1'] },
'exception' => 'Exception'
}
)
Resque::Failure.stubs(:all).with(1).returns(
{
'payload' => { 'args' => ['job_class' => 'JobClass2'] },
'exception' => 'Exception'
}
)
Resque::Failure.expects(:remove).with(0)
Resque::Failure.expects(:remove).with(1).never
visit(:destroy_all, { job_class: 'JobClass1' }, :method => :delete)
assert_redirected_to failures_path
end

it 'deletes all failures with the job exception specified' do
Resque::Failure.stubs(:count).returns(2)
Resque::Failure.stubs(:all).with(0).returns(
{
'payload' => { 'args' => ['job_class' => 'JobClass1'] },
'exception' => 'Exception1'
}
)
Resque::Failure.stubs(:all).with(1).returns(
{
'payload' => { 'args' => ['job_class' => 'JobClass2'] },
'exception' => 'Exception2'
}
)
Resque::Failure.expects(:remove).with(0).never
Resque::Failure.expects(:remove).with(1)
visit(:destroy_all, { job_exception: 'Exception2' }, :method => :delete)
assert_redirected_to failures_path
end
end

describe "PUT /failures/:id/retry" do
Expand Down Expand Up @@ -69,6 +111,50 @@ class FailuresControllerTest < ActionController::TestCase
visit(:retry_all, {:queue=>"myqueue"}, :method => :put)
assert_redirected_to failures_path(:queue=>'myqueue')
end

it 'retries all failures with the job class specified' do
Resque::Failure.stubs(:count).returns(2)
Resque::Failure.stubs(:all).with(0).returns(
{
'payload' => { 'args' => ['job_class' => 'JobClass1'] },
'exception' => 'Exception'
}
)
Resque::Failure.stubs(:all).with(1).returns(
{
'payload' => { 'args' => ['job_class' => 'JobClass2'] },
'exception' => 'Exception'
}
)
Resque::Failure.expects(:requeue).with(0)
Resque::Failure.expects(:remove).with(0)
Resque::Failure.expects(:requeue).with(1).never
Resque::Failure.expects(:remove).with(1).never
visit(:retry_all, { job_class: 'JobClass1' }, :method => :put)
assert_redirected_to failures_path
end

it 'retries all failures with the job exception specified' do
Resque::Failure.stubs(:count).returns(2)
Resque::Failure.stubs(:all).with(0).returns(
{
'payload' => { 'args' => ['job_class' => 'JobClass1'] },
'exception' => 'Exception1'
}
)
Resque::Failure.stubs(:all).with(1).returns(
{
'payload' => { 'args' => ['job_class' => 'JobClass2'] },
'exception' => 'Exception2'
}
)
Resque::Failure.expects(:requeue).with(0).never
Resque::Failure.expects(:remove).with(0).never
Resque::Failure.expects(:requeue).with(1)
Resque::Failure.expects(:remove).with(1)
visit(:retry_all, { job_exception: 'Exception2' }, :method => :put)
assert_redirected_to failures_path
end
end
end
end

0 comments on commit 7d9de03

Please sign in to comment.