Project

General

Profile

Defect #21056 » diff-v2.patch

Mizuki ISHIKAWA, 2021-06-10 07:22

View differences:

app/models/enumeration.rb
30 30

  
31 31
  before_destroy :check_integrity
32 32
  before_save    :check_default
33
  after_save     :update_children_name
33 34

  
34 35
  validates_presence_of :name
35 36
  validates_uniqueness_of :name, :scope => [:type, :project_id], :case_sensitive => true
......
136 137
    raise "Cannot delete enumeration" if self.in_use?
137 138
  end
138 139

  
140
  def update_children_name
141
    if saved_change_to_name? && self.parent_id.nil?
142
      self.class.where(name: self.name_before_last_save, parent_id: self.id).update_all(name: self.name_in_database)
143
    end
144
  end
145

  
139 146
  # Overrides Redmine::Acts::Positioned#set_default_position so that enumeration overrides
140 147
  # get the same position as the overridden enumeration
141 148
  def set_default_position
test/unit/time_entry_activity_test.rb
170 170
    assert_equal 3, other_parent_activity.reload.position
171 171
    assert_equal other_parent_activity.position, other_project_activity.reload.position
172 172
  end
173

  
174
  def test_project_activity_should_have_the_same_name_as_parent_activity
175
    parent_activity = TimeEntryActivity.find_by(name: 'Design', parent_id: nil)
176
    project = Project.find(1)
177
    project.update_or_create_time_entry_activities(
178
      {
179
        parent_activity.id.to_s => {
180
          'parent_id' => parent_activity.id.to_s,
181
          'active' => '0',
182
          'custom_field_values' => {'7' => ''}
183
        }
184
      }
185
    )
186
    project_activity = TimeEntryActivity.find_by(name: 'Design', parent_id: parent_activity.id, project_id: project.id)
187
    assert_equal parent_activity.name, project_activity.name
188

  
189
    parent_activity.update(name: 'Design1')
190
    assert_equal parent_activity.reload.name, project_activity.reload.name
191

  
192
    # When changing the name of parent_activity,
193
    # 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.
194
    project_activity.update(name: 'Design2')
195
    parent_activity.update(name: 'Design3')
196
    assert_equal 'Design2', project_activity.reload.name
197
    assert_equal 'Design3', parent_activity.reload.name
198
  end
173 199
end
(6-6/6)