diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index 08e985f..f241166 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -124,6 +124,14 @@ class ProblemsController < ApplicationController redirect_to :back end + def destroy_all + nb_problem_destroy = ProblemDestroy.execute(app.problems) + flash[:success] = "#{I18n.t(:n_errs_have, :count => nb_problem_destroy)} been deleted." + redirect_to :back + rescue ActionController::RedirectBackError + redirect_to app_path(app) + end + def search 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) selected_problems = params[:problems] || [] diff --git a/app/views/apps/edit.html.haml b/app/views/apps/edit.html.haml index 20c66cc..90199b3 100644 --- a/app/views/apps/edit.html.haml +++ b/app/views/apps/edit.html.haml @@ -1,6 +1,8 @@ - content_for :title, 'Edit App' - content_for :action_bar do = link_to_copy_attributes_from_other_app + = link_to 'delete all errs', destroy_all_app_problems_path(app), :method => :post, + :data => { :confirm => t('apps.confirm_destroy_all_problems') }, :class => 'button' = link_to 'delete application', app_path(app), :method => :delete, :data => { :confirm => t('apps.confirm_delete') }, :class => 'button' = link_to('cancel', app_path(app), :class => 'button') diff --git a/config/locales/en.yml b/config/locales/en.yml index 3b7ef75..bec6742 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -84,6 +84,7 @@ en: confirm_delete: "Permanently delete this user?" apps: confirm_delete: "Permanently delete this app?" + confirm_destroy_all_problems: "Permanently delete all of this app's errors?" index: notify: Notification Service tracker: Tracker diff --git a/config/routes.rb b/config/routes.rb index 74cd53d..c2c6b90 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,6 +30,10 @@ Errbit::Application.routes.draw do resources :notices resources :comments, :only => [:create, :destroy] + collection do + post :destroy_all + end + member do put :resolve put :unresolve diff --git a/spec/controllers/problems_controller_spec.rb b/spec/controllers/problems_controller_spec.rb index 0885ae4..7b1ac25 100644 --- a/spec/controllers/problems_controller_spec.rb +++ b/spec/controllers/problems_controller_spec.rb @@ -415,6 +415,34 @@ describe ProblemsController do }.to change(Problem, :count).by(-1) end end + + describe "POST /apps/:app_id/problems/destroy_all" do + before do + sign_in Fabricate(:admin) + @app = Fabricate(:app) + @problem1 = Fabricate(:problem, :app=>@app) + @problem2 = Fabricate(:problem, :app=>@app) + end + + it "destroys all problems" do + expect { + post :destroy_all, :app_id => @app.id + }.to change(Problem, :count).by(-2) + expect(controller.app).to eq @app + end + + it "should display a message" do + put :destroy_all, :app_id => @app.id + expect(request.flash[:success]).to match(/been deleted/) + end + + it "should redirect back to the app page" do + request.env["Referer"] = edit_app_path(@app) + put :destroy_all, :app_id => @app.id + expect(response).to redirect_to(edit_app_path(@app)) + end + end + end end diff --git a/spec/views/apps/edit.html.haml_spec.rb b/spec/views/apps/edit.html.haml_spec.rb index 7ca20e5..f917121 100644 --- a/spec/views/apps/edit.html.haml_spec.rb +++ b/spec/views/apps/edit.html.haml_spec.rb @@ -12,6 +12,11 @@ describe "apps/edit.html.haml" do view.content_for(:action_bar) end + it "should confirm the 'reset' link" do + render + expect(action_bar).to have_selector('a.button[data-confirm="%s"]' % I18n.t('apps.confirm_destroy_all_problems')) + end + it "should confirm the 'destroy' link" do render expect(action_bar).to have_selector('a.button[data-confirm="%s"]' % I18n.t('apps.confirm_delete')) -- libgit2 0.21.2