Module: TranslationAudit

Included in:
Translate
Defined in:
lib/translate/translation_audit.rb

Instance Method Summary collapse

Instance Method Details

#all_copied_fields_should_match_for(type, additional_exceptions = []) ⇒ Object



114
115
116
117
118
119
120
121
122
123
# File 'lib/translate/translation_audit.rb', line 114

def all_copied_fields_should_match_for(type, additional_exceptions = [])
  additional_exceptions << :creation_date
  compare_each(type) do |old_object, new_object| 
    next unless yield old_object, new_object if block_given?
    diff = diff_objects(old_object, new_object, additional_exceptions)
    if diff.length > 0
	self.logger.warn diff_string(old_object, new_object, additional_exceptions)
    end
  end
end

#auditObject



4
5
6
7
8
9
10
11
12
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/translate/translation_audit.rb', line 4

def audit
  logger.info "Auditing Iterations"
  audit_counts(:iteration, "Iterations")
  all_copied_fields_should_match_for :iteration  

  logger.info "Auditing Releases"
  audit_counts(:release, "Releases")
  all_copied_fields_should_match_for :release

  logger.info "Auditing Test Cases"
  audit_counts(:test_case, "Test Cases")
  all_copied_fields_should_match_for(:test_case, [:last_run]) do |old, new|
    next false unless copy_exists? old, new
    if !old.work_product.nil?
	begin
 if !equal_ignore_whitespace_and_scheduling old.work_product.name, new.work_product.name
   logger.warn "For TestCase '#{old.name}' the TestCase's work product names differ"
   logger.warn "  old work product name: #{old.work_product.name}"
   logger.warn "  new work product name: #{new.work_product.name}"
 end
	rescue Exception => e
 raise Exception.new("For test_case #{old.name} -- #{old.oid}, the new test_case had no work product")
	end
    end
  end

  logger.info "Auditing Defects"
  audit_counts(:defect, "Defects")
  all_copied_fields_should_match_for(:defect, [:closed_date, :submitted_by]) do |old, new|
    next false unless copy_exists? old, new
    if !old.requirement.nil?
	begin 
 if !equal_ignore_whitespace_and_scheduling old.requirement.name, new.requirement.name
   logger.warn "For Defect '#{old.name}' the Defect's requirement names differ"
   logger.warn "  old requirement name: #{old.requirement.name}"
   logger.warn "  new requirement name: #{new.requirement.name}"
 end
	rescue Exception => e
 raise Exception.new("For defect #{old.name}, the new defect had no requirement")
	end
    end
  end

  logger.info "Auditing Test Case Results"
  audit_counts(:test_case_result, "Test Case Results")
  all_copied_fields_should_match_for(:test_case_result, [:test_case, :tester]) do |old, new|
    next false unless copy_exists? old, new
    if !equal_ignore_whitespace_and_scheduling old.test_case.name, new.test_case.name
	logger.warn "For Test Case Result '#{old.name}' the test case names differ"
	logger.warn "  old test case name: #{old.test_case.name}"
	logger.warn "  new test case name: #{new.test_case.name}"
    end
  end      

  logger.info "Auditing Test Case Steps"
  audit_counts(:test_case_step, "Test Case Steps")
  all_copied_fields_should_match_for(:test_case_step, [:test_case]) do |old, new|
    next false unless copy_exists? old, new
    if !equal_ignore_whitespace_and_scheduling old.test_case.name, new.test_case.name
	logger.warn "For Test Case Step '#{old.name}' the test case names differ"
	logger.warn "  old test case name: #{old.test_case.name}"
	logger.warn "  new test case name: #{new.test_case.name}"
    end
  end      

  logger.info "Auditing Tasks"
  audit_counts(:task, "Tasks")
  all_copied_fields_should_match_for(:task, [:work_product]) do |old, new|
    next false unless copy_exists?(old, new) do |old_object, new_object|
	logger.warn "  task belongs to a '#{old_object.card.work_product.type}' with name '#{old_object.card.work_product.name}'" 
    end
    if !equal_ignore_whitespace_and_scheduling old.card.work_product.name, new.work_product.name
	logger.warn "For Task '#{old.name}' the work product names differ"
	logger.warn "  old work product name: #{old.card.work_product.name}"
	logger.warn "  new work product name: #{new.work_product.name}"
    end
  end

  logger.info "Auditing Features"
  compare_each :feature, :hierarchical_requirement do |old, new|
    return false unless copy_exists? old, new
  end

  logger.info "Audit complete!"
end

#audit_counts(type, type_string) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/translate/translation_audit.rb', line 90

def audit_counts(type, type_string)
  source_count = @slm.find_all(type, :workspace => @from_workspace).total_result_count
  dest_count = @slm.find_all(type, :workspace => @to_workspace).total_result_count
  logger.warn("Auditing #{type_string} counts:")
  logger.warn("  #{source_count} #{type_string} found in workspace '#{@from_workspace.name}'")
  logger.warn("  #{dest_count} #{type_string} found in workspace '#{@to_workspace.name}'")
end

#compare_each(type, new_type = type) ⇒ Object



98
99
100
101
102
103
# File 'lib/translate/translation_audit.rb', line 98

def compare_each(type, new_type = type)
  @slm.find_all(type, :workspace => @from_workspace).each do |old_object|
    new_object = @slm.find(new_type, :workspace => @to_workspace) { equal :object_i_d, TranslationStore[old_object.oid] }.first
    yield old_object, new_object
  end
end

#copy_exists?(old_object, new_object) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
# File 'lib/translate/translation_audit.rb', line 105

def copy_exists?(old_object, new_object)
  if new_object.nil?
    self.logger.warn "Cound not find a copy for object #{old_object.type} -- #{old_object.name} -- #{old_object.oid}"
    yield old_object, new_object if block_given?
    return false
  end
  true
end

#diff_objects(old_object, new_object, additional_exceptions = []) ⇒ Object



136
137
138
139
140
141
142
143
144
145
# File 'lib/translate/translation_audit.rb', line 136

def diff_objects(old_object, new_object, additional_exceptions = [])
  excepted_attributes = old_object.excepted_attributes + additional_exceptions
  old_hash = old_object.elements.reject { |k, v| excepted_attributes.include?(k) }
  new_hash = {}
  old_hash.each_key do |k|
    new_hash[k] = new_object.elements[k]
  end

  old_hash.diff(new_hash)
end

#diff_string(old, new, additional_exceptions = []) ⇒ Object



125
126
127
128
129
130
131
132
133
134
# File 'lib/translate/translation_audit.rb', line 125

def diff_string(old, new, additional_exceptions = [])
  diff = diff_objects(old, new, additional_exceptions)

  diff_string = "#{old.type} with name '#{old.name}' -- #{old.oid}:#{new.oid} differs\n"
  diff_string << "value\told\t\t\t\tnew\n"
  diff.each do |key, valye|
    diff_string << key.to_s << "\t" << old.elements[key].to_s << "\t\t\t" << new.elements[key].to_s << "\n"
  end
  diff_string
end

#equal_ignore_whitespace_and_scheduling(s1, s2) ⇒ Object



147
148
149
# File 'lib/translate/translation_audit.rb', line 147

def equal_ignore_whitespace_and_scheduling(s1, s2)
  normalized_string(s1) == normalized_string(s2)
end

#normalized_string(s) ⇒ Object



151
152
153
154
# File 'lib/translate/translation_audit.rb', line 151

def normalized_string(s)
  scheduled_string = "Scheduled child of "
  s.strip.squeeze(" ").gsub(scheduled_string, "")
end