]> source.dussan.org Git - redmine.git/commitdiff
Project specific TimeEntryActivity name not updating properly (#21056).
authorGo MAEDA <maeda@farend.jp>
Wed, 30 Jun 2021 02:39:18 +0000 (02:39 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 30 Jun 2021 02:39:18 +0000 (02:39 +0000)
Patch by Mizuki ISHIKAWA.

git-svn-id: http://svn.redmine.org/redmine/trunk@21054 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/enumeration.rb
test/unit/time_entry_activity_test.rb

index 83efea6df5a1c370d8d0cf17dac87983507d97e4..53360e5ff836b8502df034f5ace836c259220fc9 100644 (file)
@@ -30,6 +30,7 @@ class Enumeration < ActiveRecord::Base
 
   before_destroy :check_integrity
   before_save    :check_default
+  after_save     :update_children_name
 
   validates_presence_of :name
   validates_uniqueness_of :name, :scope => [:type, :project_id], :case_sensitive => true
@@ -136,6 +137,12 @@ class Enumeration < ActiveRecord::Base
     raise "Cannot delete enumeration" if self.in_use?
   end
 
+  def update_children_name
+    if saved_change_to_name? && self.parent_id.nil?
+      self.class.where(name: self.name_before_last_save, parent_id: self.id).update_all(name: self.name_in_database)
+    end
+  end
+
   # Overrides Redmine::Acts::Positioned#set_default_position so that enumeration overrides
   # get the same position as the overridden enumeration
   def set_default_position
index 83cb77f93f2be4ce72652ae2ca953faee5ab49c6..67e92585043568a2dca32ebf4b830bd9d766cbeb 100644 (file)
@@ -170,4 +170,30 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
     assert_equal 3, other_parent_activity.reload.position
     assert_equal other_parent_activity.position, other_project_activity.reload.position
   end
+
+  def test_project_activity_should_have_the_same_name_as_parent_activity
+    parent_activity = TimeEntryActivity.find_by(name: 'Design', parent_id: nil)
+    project = Project.find(1)
+    project.update_or_create_time_entry_activities(
+      {
+        parent_activity.id.to_s => {
+          'parent_id' => parent_activity.id.to_s,
+          'active' => '0',
+          'custom_field_values' => {'7' => ''}
+        }
+      }
+    )
+    project_activity = TimeEntryActivity.find_by(name: 'Design', parent_id: parent_activity.id, project_id: project.id)
+    assert_equal parent_activity.name, project_activity.name
+
+    parent_activity.update(name: 'Design1')
+    assert_equal parent_activity.reload.name, project_activity.reload.name
+
+    # When changing the name of parent_activity,
+    # if the name of parent_activity before the change and the name of project_activity do not match, the name of project_activity is not changed.
+    project_activity.update(name: 'Design2')
+    parent_activity.update(name: 'Design3')
+    assert_equal 'Design2', project_activity.reload.name
+    assert_equal 'Design3', parent_activity.reload.name
+  end
 end