Class: TestCaseCopy

Inherits:
ObjectCopy show all
Defined in:
lib/translate/copy/test_case_copy.rb

Instance Method Summary collapse

Methods inherited from ObjectCopy

#copy, #create_object, #excluded_attributes, #fetch_object, #fetch_project, #find_project_in_new_workspace, #initialize, #remember, #shallow_copy, #user_exists?

Constructor Details

This class inherits a constructor from ObjectCopy

Instance Method Details

#copy_children(new_workspace) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/translate/copy/test_case_copy.rb', line 3

def copy_children(new_workspace)
  @object.results.each do |result|
    result.copy(new_workspace, :test_case => @new_object)
  end unless @object.results.nil?

  @object.steps.each do |step|
    step.copy(new_workspace, :test_case => @new_object)
  end unless @object.steps.nil?
end

#tangle(new_workspace) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/translate/copy/test_case_copy.rb', line 13

def tangle(new_workspace)
  
  values = {}
  if  !@object.work_product.nil? && @object.work_product.type == "Story"
    # if the old test case has a work product
    new_test_case = fetch_object(:test_case, @object.oid, new_workspace)
    # get the new test case copied from this testcase
    new_work_product = fetch_object(:artifact, @object.work_product.oid, new_workspace)

    values[:work_product] = new_work_product


    
    # If the original test_case is in a different project from the stories' card,
    # then create a new user story, as the parent of this new user story, and make
    # the work_product on the test case the new parent
    if @object.work_product != nil && @object.work_product.cards != nil &&  # The TC has a work_product, that is scheduled
 @object.project != nil &&                                           # The TC in not in the parent project
    	  @object.work_product.cards.first.project != @object.project         # The card in in a different project from the test_case

	story_name = @object.work_product.name
	parent_story = new_workspace.rally_rest.create(:hierarchical_requirement, 
				       :workspace => new_workspace,
				       :project => nil,
				       :name => "Parent story for #{story_name} to hold test cases in project #{@object.project.name}")
	new_work_product.update(:parent => parent_story)
	values[:work_product] = parent_story

    # if the new test case is in the Parent Project and 
    # the new work_product is not in the same project as the test case, 
    # then put the test case in the same project as the work_product
    elsif new_test_case.project.nil? && new_test_case.project != new_work_product.project
	values[:project] = new_work_product.project
    end
    
    
    # update the new test case
    new_test_case.update(values) unless values.length == 0
  end
end