From: Go MAEDA Date: Wed, 30 Jun 2021 02:39:18 +0000 (+0000) Subject: Project specific TimeEntryActivity name not updating properly (#21056). X-Git-Tag: 5.0.0~357 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9101dcf11101ef5838dfc06ed3f4c4238d2d11c5;p=redmine.git Project specific TimeEntryActivity name not updating properly (#21056). Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@21054 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index 83efea6df..53360e5ff 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -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 diff --git a/test/unit/time_entry_activity_test.rb b/test/unit/time_entry_activity_test.rb index 83cb77f93..67e925850 100644 --- a/test/unit/time_entry_activity_test.rb +++ b/test/unit/time_entry_activity_test.rb @@ -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