Project

General

Profile

Defect #33289 ยป 33289.patch

Mizuki ISHIKAWA, 2020-09-03 07:45

View differences:

app/models/enumeration.rb
24 24

  
25 25
  belongs_to :project
26 26

  
27
  acts_as_positioned :scope => :parent_id
27
  acts_as_positioned :scope => %i[project_id parent_id]
28 28
  acts_as_customizable
29 29
  acts_as_tree
30 30

  
......
149 149
  # position as the overridden enumeration
150 150
  def update_position
151 151
    super
152
    if saved_change_to_position?
152
    if saved_change_to_position? && self.parent_id.nil?
153 153
      self.class.where.not(:parent_id => nil).update_all(
154 154
        "position = coalesce((
155 155
          select position
test/unit/time_entry_activity_test.rb
131 131
    assert_include activity, project.activities
132 132
    assert_include TimeEntryActivity.find(9), project.activities
133 133
  end
134

  
135
  def test_project_activity_should_have_the_same_position_as_the_position_of_the_parent_activity
136
    project = Project.find(1)
137

  
138
    parent_activity = TimeEntryActivity.find_by(position: 3, parent_id: nil)
139
    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' => ''}}})
140
    project_activity = TimeEntryActivity.find_by(position: 3, parent_id: parent_activity.id, project_id: 1)
141
    assert_equal parent_activity.position, project_activity.position
142

  
143
    # Changing the position of the parent activity also changes the position of the activity in each project.
144
    other_parent_activity = TimeEntryActivity.find_by(position: 4, parent_id: nil)
145
    project.update_or_create_time_entry_activities({other_parent_activity.id.to_s => {'parent_id' => other_parent_activity.id.to_s, 'active' => '0', 'custom_field_values' => {'7' => ''}}})
146
    other_project_activity = TimeEntryActivity.find_by(position: 4, parent_id: other_parent_activity.id, project_id: 1)
147

  
148
    parent_activity.update(position: 4)
149
    assert_equal 4, parent_activity.reload.position
150
    assert_equal parent_activity.position, project_activity.reload.position
151
    assert_equal 3, other_parent_activity.reload.position
152
    assert_equal other_parent_activity.position, other_project_activity.reload.position
153
  end
134 154
end
    (1-1/1)