36361.patch

Yuichi HARADA, 2021-12-27 08:17

Download (3.9 KB)

View differences:

test/unit/project_copy_test.rb
173 173
  end
174 174

  
175 175
  test "#copy should copy issue relations" do
176
    Setting.cross_project_issue_relations = '1'
177

  
178
    second_issue = Issue.generate!(:status_id => 5,
179
                                   :subject => "copy issue relation",
180
                                   :tracker_id => 1,
181
                                   :assigned_to_id => 2,
182
                                   :project_id => @source_project.id)
183
    source_relation = IssueRelation.create!(:issue_from => Issue.find(4),
176
    with_settings :cross_project_issue_relations => '1' do
177
      second_issue = Issue.generate!(:status_id => 5,
178
                                     :subject => "copy issue relation",
179
                                     :tracker_id => 1,
180
                                     :assigned_to_id => 2,
181
                                     :project_id => @source_project.id)
182
      source_relation = IssueRelation.create!(:issue_from => Issue.find(4),
184 183
                                              :issue_to => second_issue,
185 184
                                              :relation_type => "relates")
186
    source_relation_cross_project = IssueRelation.create!(:issue_from => Issue.find(1),
185
      source_relation_cross_project = IssueRelation.create!(:issue_from => Issue.find(1),
187 186
                                                            :issue_to => second_issue,
188 187
                                                            :relation_type => "duplicates")
189 188

  
190
    assert @project.copy(@source_project)
191
    assert_equal @source_project.issues.count, @project.issues.count
192
    copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4
193
    copied_second_issue = @project.issues.find_by_subject("copy issue relation")
194

  
195
    # First issue with a relation on project
196
    assert_equal 1, copied_issue.relations.size, "Relation not copied"
197
    copied_relation = copied_issue.relations.first
198
    assert_equal "relates", copied_relation.relation_type
199
    assert_equal copied_second_issue.id, copied_relation.issue_to_id
200
    assert_not_equal source_relation.id, copied_relation.id
201

  
202
    # Second issue with a cross project relation
203
    assert_equal 2, copied_second_issue.relations.size, "Relation not copied"
204
    copied_relation = copied_second_issue.relations.find {|r| r.relation_type == 'duplicates'}
205
    assert_equal "duplicates", copied_relation.relation_type
206
    assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept"
207
    assert_not_equal source_relation_cross_project.id, copied_relation.id
189
      assert @project.copy(@source_project)
190
      assert_equal @source_project.issues.count, @project.issues.count
191
      copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4
192
      copied_second_issue = @project.issues.find_by_subject("copy issue relation")
193

  
194
      # First issue with a relation on project
195
      assert_equal 1, copied_issue.relations.size, "Relation not copied"
196
      copied_relation = copied_issue.relations.first
197
      assert_equal "relates", copied_relation.relation_type
198
      assert_equal copied_second_issue.id, copied_relation.issue_to_id
199
      assert_not_equal source_relation.id, copied_relation.id
200

  
201
      # Second issue with a cross project relation
202
      assert_equal 2, copied_second_issue.relations.size, "Relation not copied"
203
      copied_relation = copied_second_issue.relations.find {|r| r.relation_type == 'duplicates'}
204
      assert_equal "duplicates", copied_relation.relation_type
205
      assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept"
206
      assert_not_equal source_relation_cross_project.id, copied_relation.id
207
    end
208 208
  end
209 209

  
210 210
  test "#copy should copy issue attachments" do