Skip to content

Commit

Permalink
Preserve page filter when deleting execution (#381)
Browse files Browse the repository at this point in the history
Example: when deleting jobs one by one with error state it is now easier as we redirect back to the same page
  • Loading branch information
morgoth authored Sep 18, 2021
1 parent 4d0fab3 commit 9b677f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion engine/app/controllers/good_job/active_jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion engine/app/controllers/good_job/executions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions spec/system/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9b677f4

Please sign in to comment.