Project

General

Profile

Defect #5700 » 5700.diff

Jan from Planio www.plan.io, 2010-06-20 20:27

View differences:

app/controllers/timelog_controller.rb
225 225
  def destroy
226 226
    (render_404; return) unless @time_entry
227 227
    (render_403; return) unless @time_entry.editable_by?(User.current)
228
    @time_entry.destroy
229
    flash[:notice] = l(:notice_successful_delete)
228
    begin
229
      @time_entry.destroy
230
      flash[:notice] = l(:notice_successful_delete)
231
    rescue
232
      flash[:error] = l(:notice_unable_delete_time_entry)
233
    end
230 234
    redirect_to :back
231 235
  rescue ::ActionController::RedirectBackError
232 236
    redirect_to :action => 'details', :project_id => @time_entry.project
config/locales/de.yml
175 175
  notice_account_pending: "Ihr Konto wurde erstellt und wartet jetzt auf die Genehmigung des Administrators."
176 176
  notice_default_data_loaded: Die Standard-Konfiguration wurde erfolgreich geladen.
177 177
  notice_unable_delete_version: Die Version konnte nicht gelöscht werden.
178
  notice_unable_delete_time_entry: Der Zeiterfassungseintrag konnte nicht gelöscht werden.
178 179
  notice_issue_done_ratios_updated: Der Ticket-Fortschritt wurde aktualisiert.
179 180

  
180 181
  error_can_t_load_default_data: "Die Standard-Konfiguration konnte nicht geladen werden: {{value}}"
config/locales/en.yml
153 153
  notice_account_pending: "Your account was created and is now pending administrator approval."
154 154
  notice_default_data_loaded: Default configuration successfully loaded.
155 155
  notice_unable_delete_version: Unable to delete version.
156
  notice_unable_delete_time_entry: Unable to delete time log entry.
156 157
  notice_issue_done_ratios_updated: Issue done ratios updated.
157 158
  
158 159
  error_can_t_load_default_data: "Default configuration could not be loaded: {{value}}"
test/functional/timelog_controller_test.rb
116 116
    @request.session[:user_id] = 2
117 117
    post :destroy, :id => 1
118 118
    assert_redirected_to :action => 'details', :project_id => 'ecookbook'
119
    assert_equal I18n.t(:notice_successful_delete), flash[:notice]
119 120
    assert_nil TimeEntry.find_by_id(1)
120 121
  end
121 122
  
123
  def test_destroy_should_fail
124
    # simulate that this fails (e.g. due to a plugin), see #5700
125
    TimeEntry.class_eval do
126
      before_destroy :produce_some_error
127
      def produce_some_error ; raise ; end
128
    end
129

  
130
    @request.session[:user_id] = 2
131
    post :destroy, :id => 1
132
    assert_redirected_to :action => 'details', :project_id => 'ecookbook'
133
    assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
134
    assert_not_nil TimeEntry.find_by_id(1)
135

  
136
    # remove the error simulation
137
    TimeEntry.before_destroy.reject! {|callback| callback.method == :produce_some_error }
138
  end
139
  
122 140
  def test_report_no_criteria
123 141
    get :report, :project_id => 1
124 142
    assert_response :success
(1-1/2)