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
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}}"
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}}"
@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