From 846045fd05909689644f4858897ac3fda7fdac36 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 14 Jun 2008 12:31:32 +0000 Subject: [PATCH] Fixed: time entries created with the default activity even if a different one is specified (#1302). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1533 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/time_entry.rb | 6 ++++-- test/functional/timelog_controller_test.rb | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 4bd2d33b8..b234a8b21 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -30,8 +30,10 @@ class TimeEntry < ActiveRecord::Base validates_length_of :comments, :maximum => 255 def after_initialize - if new_record? - self.activity ||= Enumeration.default('ACTI') + if new_record? && self.activity.nil? + if default_activity = Enumeration.default('ACTI') + self.activity_id = default_activity.id + end end end diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 479f4f44f..c8b47cf8d 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -44,7 +44,8 @@ class TimelogControllerTest < Test::Unit::TestCase @request.session[:user_id] = 3 post :edit, :project_id => 1, :time_entry => {:comments => 'Some work on TimelogControllerTest', - :activity_id => '10', + # Not the default activity + :activity_id => '11', :spent_on => '2008-03-14', :issue_id => '1', :hours => '7.3'} @@ -53,6 +54,7 @@ class TimelogControllerTest < Test::Unit::TestCase i = Issue.find(1) t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') assert_not_nil t + assert_equal 11, t.activity_id assert_equal 7.3, t.hours assert_equal 3, t.user_id assert_equal i, t.issue