Class: StoryCopy

Inherits:
RequirementCopy show all
Defined in:
lib/translate/copy/story_copy.rb

Instance Method Summary collapse

Methods inherited from RequirementCopy

#dependent_in_correct_project?, #in_child_project?, #in_different_child_projects?, #in_same_project?, #project_name, #type_as_symbol

Methods inherited from ObjectCopy

#card_values, #copy, #excluded_attributes, #fetch_object, #fetch_project, #initialize, #logger, #new_workspace, #rally_rest, #remember, #tangle, #type_as_symbol, #user_exists?

Constructor Details

This class inherits a constructor from ObjectCopy

Instance Method Details

#any_test_cases_or_defects_in_different_project_than_card?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
# File 'lib/translate/copy/story_copy.rb', line 53

def any_test_cases_or_defects_in_different_project_than_card?
  return false unless @object.cards
  projects = collect_test_case_and_defect_projects
  return false if projects.length == 0
  card_project = @object.cards.first.project

  not projects.include? card_project
end

#collect_projects_from_defectsObject



75
76
77
78
79
# File 'lib/translate/copy/story_copy.rb', line 75

def collect_projects_from_defects
  object = @object
  results = rally_rest.find(:defect, :workspace => @object.workspace) { equal :requirement, object }
  results.map { |tc| tc.project }
end

#collect_projects_from_test_caseObject



69
70
71
72
73
# File 'lib/translate/copy/story_copy.rb', line 69

def collect_projects_from_test_case
  object = @object
  results = rally_rest.find(:test_case, :workspace => @object.workspace) { equal :work_product, object }
  results.map { |tc| tc.project }
end

#collect_test_case_and_defect_projectsObject



62
63
64
65
66
67
# File 'lib/translate/copy/story_copy.rb', line 62

def collect_test_case_and_defect_projects
  projects = Set.new
  projects.merge collect_projects_from_test_case
  projects.merge collect_projects_from_defects
  projects
end

#copy_childrenObject



40
41
42
43
44
# File 'lib/translate/copy/story_copy.rb', line 40

def copy_children
  @object.cards.first.tasks.each do |task|
    task.copy(new_workspace, :work_product => @new_object)
  end if !@object.cards.nil? && !@object.cards.first.tasks.nil?
end

#create_object(values) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/translate/copy/story_copy.rb', line 17

def create_object(values)
  new_object = rally_rest.create(:hierarchical_requirement, values)
 
  if @object.cards && create_user_story_from_card?
    logger.warn "For '#{@object.type}' with name '#{@object.name}' we have created two User Stories in the new workspace because this Story has Test Cases and/or Defects attached to that are in different projects than the project the card was schedule in."
    @object.cards.first.copy(new_workspace, :parent => new_object)
  end
  new_object
end

#create_user_story_from_card?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/translate/copy/story_copy.rb', line 46

def create_user_story_from_card?
  unless defined? @create_user_story_from_card 
    @create_user_story_from_card = any_test_cases_or_defects_in_different_project_than_card?
  end
  @create_user_story_from_card 
end

#find_project_in_new_workspaceObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/translate/copy/story_copy.rb', line 27

def find_project_in_new_workspace
  if @object.cards.nil?
    return super
  elsif create_user_story_from_card?
    return super
  elsif @object.cards.first.project.nil?
    return super 
  else
    fetch_project @object.cards.first.project.name
  end
end

#shallow_copy(object) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/translate/copy/story_copy.rb', line 5

def shallow_copy(object)
  values = super
  if @object.cards && !create_user_story_from_card?
    logger.debug "Requirement copy only have one card"
    card_values = card_values(object.cards.first)
    logger.debug card_values.inspect
    values.merge! card_values
    logger.debug values.inspect
  end
  values
end