Commit 32803349237935f84c821addb58a0995bda34097

Authored by Tony Spataro
1 parent 9a4dd080
Exists in master and in 1 other branch production

Give admins the ability to destroy all problems associated with an app

app/controllers/problems_controller.rb
... ... @@ -124,6 +124,14 @@ class ProblemsController < ApplicationController
124 124 redirect_to :back
125 125 end
126 126  
  127 + def destroy_all
  128 + nb_problem_destroy = ProblemDestroy.execute(app.problems)
  129 + flash[:success] = "#{I18n.t(:n_errs_have, :count => nb_problem_destroy)} been deleted."
  130 + redirect_to :back
  131 + rescue ActionController::RedirectBackError
  132 + redirect_to app_path(app)
  133 + end
  134 +
127 135 def search
128 136 ps = Problem.search(params[:search]).for_apps(app_scope).in_env(params[:environment]).all_else_unresolved(params[:all_errs]).ordered_by(params_sort, params_order)
129 137 selected_problems = params[:problems] || []
... ...
app/views/apps/edit.html.haml
1 1 - content_for :title, 'Edit App'
2 2 - content_for :action_bar do
3 3 = link_to_copy_attributes_from_other_app
  4 + = link_to 'delete all errs', destroy_all_app_problems_path(app), :method => :post,
  5 + :data => { :confirm => t('apps.confirm_destroy_all_problems') }, :class => 'button'
4 6 = link_to 'delete application', app_path(app), :method => :delete,
5 7 :data => { :confirm => t('apps.confirm_delete') }, :class => 'button'
6 8 = link_to('cancel', app_path(app), :class => 'button')
... ...
config/locales/en.yml
... ... @@ -84,6 +84,7 @@ en:
84 84 confirm_delete: "Permanently delete this user?"
85 85 apps:
86 86 confirm_delete: "Permanently delete this app?"
  87 + confirm_destroy_all_problems: "Permanently delete all of this app's errors?"
87 88 index:
88 89 notify: Notification Service
89 90 tracker: Tracker
... ...
config/routes.rb
... ... @@ -30,6 +30,10 @@ Errbit::Application.routes.draw do
30 30 resources :notices
31 31 resources :comments, :only => [:create, :destroy]
32 32  
  33 + collection do
  34 + post :destroy_all
  35 + end
  36 +
33 37 member do
34 38 put :resolve
35 39 put :unresolve
... ...
spec/controllers/problems_controller_spec.rb
... ... @@ -415,6 +415,34 @@ describe ProblemsController do
415 415 }.to change(Problem, :count).by(-1)
416 416 end
417 417 end
  418 +
  419 + describe "POST /apps/:app_id/problems/destroy_all" do
  420 + before do
  421 + sign_in Fabricate(:admin)
  422 + @app = Fabricate(:app)
  423 + @problem1 = Fabricate(:problem, :app=>@app)
  424 + @problem2 = Fabricate(:problem, :app=>@app)
  425 + end
  426 +
  427 + it "destroys all problems" do
  428 + expect {
  429 + post :destroy_all, :app_id => @app.id
  430 + }.to change(Problem, :count).by(-2)
  431 + expect(controller.app).to eq @app
  432 + end
  433 +
  434 + it "should display a message" do
  435 + put :destroy_all, :app_id => @app.id
  436 + expect(request.flash[:success]).to match(/been deleted/)
  437 + end
  438 +
  439 + it "should redirect back to the app page" do
  440 + request.env["Referer"] = edit_app_path(@app)
  441 + put :destroy_all, :app_id => @app.id
  442 + expect(response).to redirect_to(edit_app_path(@app))
  443 + end
  444 + end
  445 +
418 446 end
419 447  
420 448 end
... ...
spec/views/apps/edit.html.haml_spec.rb
... ... @@ -12,6 +12,11 @@ describe "apps/edit.html.haml" do
12 12 view.content_for(:action_bar)
13 13 end
14 14  
  15 + it "should confirm the 'reset' link" do
  16 + render
  17 + expect(action_bar).to have_selector('a.button[data-confirm="%s"]' % I18n.t('apps.confirm_destroy_all_problems'))
  18 + end
  19 +
15 20 it "should confirm the 'destroy' link" do
16 21 render
17 22 expect(action_bar).to have_selector('a.button[data-confirm="%s"]' % I18n.t('apps.confirm_delete'))
... ...