summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/timelog_controller.rb7
-rw-r--r--config/locales/de.yml1
-rw-r--r--config/locales/en.yml1
-rw-r--r--test/functional/timelog_controller_test.rb18
4 files changed, 25 insertions, 2 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index 160c19974..73ff58b82 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -225,8 +225,11 @@ class TimelogController < ApplicationController
def destroy
(render_404; return) unless @time_entry
(render_403; return) unless @time_entry.editable_by?(User.current)
- @time_entry.destroy
- flash[:notice] = l(:notice_successful_delete)
+ if @time_entry.destroy && @time_entry.destroyed?
+ flash[:notice] = l(:notice_successful_delete)
+ else
+ flash[:error] = l(:notice_unable_delete_time_entry)
+ end
redirect_to :back
rescue ::ActionController::RedirectBackError
redirect_to :action => 'details', :project_id => @time_entry.project
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 0e7e4c074..16b00d00b 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -175,6 +175,7 @@ de:
notice_account_pending: "Ihr Konto wurde erstellt und wartet jetzt auf die Genehmigung des Administrators."
notice_default_data_loaded: Die Standard-Konfiguration wurde erfolgreich geladen.
notice_unable_delete_version: Die Version konnte nicht gelöscht werden.
+ notice_unable_delete_time_entry: Der Zeiterfassungseintrag konnte nicht gelöscht werden.
notice_issue_done_ratios_updated: Der Ticket-Fortschritt wurde aktualisiert.
error_can_t_load_default_data: "Die Standard-Konfiguration konnte nicht geladen werden: {{value}}"
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 91ef3fa97..9d875e4b4 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -153,6 +153,7 @@ en:
notice_account_pending: "Your account was created and is now pending administrator approval."
notice_default_data_loaded: Default configuration successfully loaded.
notice_unable_delete_version: Unable to delete version.
+ notice_unable_delete_time_entry: Unable to delete time log entry.
notice_issue_done_ratios_updated: Issue done ratios updated.
error_can_t_load_default_data: "Default configuration could not be loaded: {{value}}"
diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb
index 880527319..9e30a0ae8 100644
--- a/test/functional/timelog_controller_test.rb
+++ b/test/functional/timelog_controller_test.rb
@@ -116,9 +116,27 @@ class TimelogControllerTest < ActionController::TestCase
@request.session[:user_id] = 2
post :destroy, :id => 1
assert_redirected_to :action => 'details', :project_id => 'ecookbook'
+ assert_equal I18n.t(:notice_successful_delete), flash[:notice]
assert_nil TimeEntry.find_by_id(1)
end
+ def test_destroy_should_fail
+ # simulate that this fails (e.g. due to a plugin), see #5700
+ TimeEntry.class_eval do
+ before_destroy :stop_callback_chain
+ def stop_callback_chain ; return false ; end
+ end
+
+ @request.session[:user_id] = 2
+ post :destroy, :id => 1
+ assert_redirected_to :action => 'details', :project_id => 'ecookbook'
+ assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
+ assert_not_nil TimeEntry.find_by_id(1)
+
+ # remove the simulation
+ TimeEntry.before_destroy.reject! {|callback| callback.method == :stop_callback_chain }
+ end
+
def test_report_no_criteria
get :report, :project_id => 1
assert_response :success