Browse Source

Handle unsuccessful destroys in TimelogController. #5700

Contributed by Jan

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3805 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/1.0.0
Eric Davis 14 years ago
parent
commit
c98f46d691

+ 5
- 2
app/controllers/timelog_controller.rb View File

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

+ 1
- 0
config/locales/de.yml View File

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

+ 1
- 0
config/locales/en.yml View File

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

+ 18
- 0
test/functional/timelog_controller_test.rb View File

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

Loading…
Cancel
Save