]> source.dussan.org Git - redmine.git/commitdiff
Merged r11762 and r11763 from trunk (#13783).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 12 May 2013 09:43:59 +0000 (09:43 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 12 May 2013 09:43:59 +0000 (09:43 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.3-stable@11835 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/enumerations_controller.rb
app/models/enumeration.rb
app/models/time_entry_activity.rb
test/object_helpers.rb
test/unit/time_entry_activity_test.rb

index 4e5475becc35cfe1a85a75735af20affd4966a9f..125e87cff86422f7e7bb4ca6f1ec8d6ef67b00c0 100644 (file)
@@ -77,7 +77,7 @@ class EnumerationsController < ApplicationController
         return
       end
     end
-    @enumerations = @enumeration.class.all - [@enumeration]
+    @enumerations = @enumeration.class.system.all - [@enumeration]
   end
 
   private
index 1946735ec8baf5bd8e33e9aac9c4311cabad3b37..7e8bf5a81cd922e7aac6ef371275ab27986b80d0 100644 (file)
@@ -38,6 +38,7 @@ class Enumeration < ActiveRecord::Base
   scope :shared, lambda { where(:project_id => nil) }
   scope :sorted, lambda { order("#{table_name}.position ASC") }
   scope :active, lambda { where(:active => true) }
+  scope :system, lambda { where(:project_id => nil) }
   scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
 
   def self.default
index f2a18d1d016dbf82a852215fe16cae2681dd3b6a..58a6de13d911e075ca9ebd562087f9fc61023a19 100644 (file)
@@ -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
index 0b6ec01d8982600048a64c7665f010ab2f377019..41d6b18927df8488c7c7240dfa0ad69b7ecaf175 100644 (file)
@@ -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
index 3a7547415c439eef36160fc10bd7a62d752682fb..a094c84caba9430f8388db8c4a2db348e512ad55 100644 (file)
@@ -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