diff --git a/engine/app/controllers/good_job/active_jobs_controller.rb b/engine/app/controllers/good_job/active_jobs_controller.rb index 0dbb55b4b..269145745 100644 --- a/engine/app/controllers/good_job/active_jobs_controller.rb +++ b/engine/app/controllers/good_job/active_jobs_controller.rb @@ -4,7 +4,7 @@ class ActiveJobsController < GoodJob::BaseController def show @executions = GoodJob::Execution.active_job_id(params[:id]) .order(Arel.sql("COALESCE(scheduled_at, created_at) DESC")) - raise ActiveRecord::RecordNotFound if @executions.empty? + redirect_to root_path, alert: "Executions for Active Job #{params[:id]} not found" if @executions.empty? end end end diff --git a/engine/app/controllers/good_job/executions_controller.rb b/engine/app/controllers/good_job/executions_controller.rb index 1689cb85b..073b1110c 100644 --- a/engine/app/controllers/good_job/executions_controller.rb +++ b/engine/app/controllers/good_job/executions_controller.rb @@ -4,7 +4,7 @@ class ExecutionsController < GoodJob::BaseController def destroy deleted_count = GoodJob::Execution.where(id: params[:id]).delete_all message = deleted_count.positive? ? { notice: "Job execution deleted" } : { alert: "Job execution not deleted" } - redirect_to root_path, **message + redirect_back fallback_location: root_path, **message end end end diff --git a/spec/system/dashboard_spec.rb b/spec/system/dashboard_spec.rb index ad14c4aad..343b7c6c8 100644 --- a/spec/system/dashboard_spec.rb +++ b/spec/system/dashboard_spec.rb @@ -19,4 +19,19 @@ expect(page).to have_content 'Job execution deleted' expect(page).not_to have_content 'ExampleJob' end + + it 'deletes job redirecting back to applied filter' do + ActiveJob::Base.queue_adapter = GoodJob::Adapter.new(execution_mode: :external) + + ExampleJob.perform_later + + visit '/good_job' + click_link 'unfinished' + expect(page).to have_content 'ExampleJob' + + click_button('Delete execution') + expect(page).to have_content 'Job execution deleted' + expect(page).not_to have_content 'ExampleJob' + expect(current_url).to match %r{/good_job/\?state=unfinished} + end end