summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/time_entry_activity.rb8
-rw-r--r--test/object_helpers.rb3
-rw-r--r--test/unit/time_entry_activity_test.rb30
3 files changed, 37 insertions, 4 deletions
diff --git a/app/models/time_entry_activity.rb b/app/models/time_entry_activity.rb
index f2a18d1d0..58a6de13d 100644
--- a/app/models/time_entry_activity.rb
+++ b/app/models/time_entry_activity.rb
@@ -24,11 +24,15 @@ class TimeEntryActivity < Enumeration
OptionName
end
+ def objects
+ TimeEntry.where(:activity_id => self_and_descendants(1).map(&:id))
+ end
+
def objects_count
- time_entries.count
+ objects.count
end
def transfer_relations(to)
- time_entries.update_all("activity_id = #{to.id}")
+ objects.update_all(:activity_id => to.id)
end
end
diff --git a/test/object_helpers.rb b/test/object_helpers.rb
index 8c82a328b..2f29793f2 100644
--- a/test/object_helpers.rb
+++ b/test/object_helpers.rb
@@ -107,10 +107,11 @@ module ObjectHelpers
def TimeEntry.generate!(attributes={})
entry = TimeEntry.new(attributes)
entry.user ||= User.find(2)
- entry.issue ||= Issue.find(1)
+ entry.issue ||= Issue.find(1) unless entry.project
entry.project ||= entry.issue.project
entry.activity ||= TimeEntryActivity.first
entry.spent_on ||= Date.today
+ entry.hours ||= 1.0
entry.save!
entry
end
diff --git a/test/unit/time_entry_activity_test.rb b/test/unit/time_entry_activity_test.rb
index 3a7547415..a094c84ca 100644
--- a/test/unit/time_entry_activity_test.rb
+++ b/test/unit/time_entry_activity_test.rb
@@ -84,5 +84,33 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
e.reload
assert_equal "0", e.custom_value_for(field).value
end
-end
+ def test_system_activity_with_child_in_use_should_be_in_use
+ project = Project.generate!
+ system_activity = TimeEntryActivity.create!(:name => 'Activity')
+ project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
+
+ TimeEntry.generate!(:project => project, :activity => project_activity)
+
+ assert project_activity.in_use?
+ assert system_activity.in_use?
+ end
+
+ def test_destroying_a_system_activity_should_reassign_children_activities
+ project = Project.generate!
+ system_activity = TimeEntryActivity.create!(:name => 'Activity')
+ project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
+
+ entries = [
+ TimeEntry.generate!(:project => project, :activity => system_activity),
+ TimeEntry.generate!(:project => project, :activity => project_activity)
+ ]
+
+ assert_difference 'TimeEntryActivity.count', -2 do
+ assert_nothing_raised do
+ assert system_activity.destroy(TimeEntryActivity.find_by_name('Development'))
+ end
+ end
+ assert entries.all? {|entry| entry.reload.activity.name == 'Development'}
+ end
+end