- test "cancelling a cancelled job stays cancelled" do
- # We need to verify that "cancel" creates a trigger file, so first
- # let's make sure there is no stale trigger file.
- begin
- File.unlink(Rails.configuration.crunch_refresh_trigger)
- rescue Errno::ENOENT
- end
-
- authorize_with :active
- put :update, {
- id: jobs(:running).uuid,
- job: {
- state: 'Cancelled'
- }
- }
- job = JSON.parse(@response.body)
- assert_not_nil job['cancelled_at'], 'cancelled again job did not stay cancelled'
- assert_equal job['state'], 'Cancelled', 'cancelled again job state not cancelled'
- end
+ [
+ [:put, :update, {job:{cancelled_at: Time.now}}, :success],
+ [:put, :update, {job:{cancelled_at: nil}}, :unprocessable_entity],
+ [:put, :update, {job:{state: 'Cancelled'}}, :success],
+ [:put, :update, {job:{state: 'Queued'}}, :unprocessable_entity],
+ [:put, :update, {job:{state: 'Running'}}, :unprocessable_entity],
+ [:put, :update, {job:{state: 'Failed'}}, :unprocessable_entity],
+ [:put, :update, {job:{state: 'Complete'}}, :unprocessable_entity],
+ [:post, :cancel, {}, :success],
+ ].each do |http_method, action, params, expected_response|
+ test "cancelled job stays cancelled after #{[http_method, action, params].inspect}" do
+ # We need to verify that "cancel" creates a trigger file, so first
+ # let's make sure there is no stale trigger file.
+ begin
+ File.unlink(Rails.configuration.crunch_refresh_trigger)
+ rescue Errno::ENOENT
+ end