Project

General

Profile

Defect #13118 » tc_redmine_defect_13118.rb

to reproduce the bad case and the solution - Thomas Kohler, 2013-02-11 22:17

 
1
require File.dirname(__FILE__) + '/../test_helper_for_redmine_defects.rb'
2

    
3
class TcRedmineDefect13118 < ActiveSupport::TestCase
4
  #http://www.redmine.org/issues/13118
5
  
6
  def test_for_defect_13118_badcase1
7
    th=TestHelperForRedmineDefects.new()
8
    new_project = th.create_project("pft1", "Project for test defect 13118", nil, nil)
9
    new_tracker=th.create_tracker("Tracker4Test13118")
10
    #add the requested tracker to the requested project
11
    if !new_project.trackers.include?(new_tracker)
12
      new_project.trackers.push(new_tracker)
13
    end
14
    new_user=th.create_user("usr4defect13118")
15
    new_issue=th.create_issue("issue4defect13118",new_tracker,new_project,new_user)
16
    a_issue_custom_field1=th.create_issue_custom_field("EffortRemaining2","int",new_issue)
17
    new_issue = update_custom_value_in_issue_intern1(new_issue, a_issue_custom_field1, "1.0")
18
    new_issue.save    
19
    # import attribute 2
20
    a_issue_custom_field=th.create_issue_custom_field("Difficulty2","string",new_issue)
21
    new_issue = update_custom_value_in_issue_intern1(new_issue, a_issue_custom_field, "Medium")
22
    new_issue.save
23
  end
24
  
25
  def test_for_defect_13118_badcase2
26
      th=TestHelperForRedmineDefects.new()
27
      new_project = th.create_project("pft1", "Project for test defect 13118", nil, nil)
28
      new_tracker=th.create_tracker("Tracker4Test13118")
29
      #add the requested tracker to the requested project
30
      if !new_project.trackers.include?(new_tracker)
31
        new_project.trackers.push(new_tracker)
32
      end
33
      new_user=th.create_user("usr4defect13118")
34
      new_issue=th.create_issue("issue4defect13118",new_tracker,new_project,new_user)
35
      a_issue_custom_field1=th.create_issue_custom_field("EffortRemaining2","int",new_issue)
36
      new_issue = update_custom_value_in_issue_intern2(new_issue, a_issue_custom_field1, "1.0")
37
      new_issue.save    
38
      # import attribute 2
39
      a_issue_custom_field=th.create_issue_custom_field("Difficulty2","string",new_issue)
40
      new_issue = update_custom_value_in_issue_intern2(new_issue, a_issue_custom_field, "Medium")
41
      new_issue.save
42
    end
43
  
44
  def test_for_defect_13118_goodcase
45
      th=TestHelperForRedmineDefects.new()
46
      new_project = th.create_project("pft1", "Project for test defect 13118", nil, nil)
47
      new_tracker=th.create_tracker("Tracker4Test13118")
48
      #add the requested tracker to the requested project
49
      if !new_project.trackers.include?(new_tracker)
50
        new_project.trackers.push(new_tracker)
51
      end
52
      new_user=th.create_user("usr4defect13118")
53
      new_issue=th.create_issue("issue4defect13118",new_tracker,new_project,new_user)
54
      a_issue_custom_field1=th.create_issue_custom_field("EffortRemaining2","int",new_issue)
55
      new_issue = update_custom_value_in_issue_intern1(new_issue, a_issue_custom_field1, "1.0")
56
      new_issue.save
57
      new_issue.reload #this save the day
58
      # import attribute 2
59
      a_issue_custom_field=th.create_issue_custom_field("Difficulty2","string",new_issue)
60
      new_issue = update_custom_value_in_issue_intern1(new_issue, a_issue_custom_field, "Medium")
61
      new_issue.save
62
    end
63
  
64
private
65

    
66
  def update_custom_value_in_issue_intern1(a_issue, a_custom_field, the_value)
67
    #against bug in redmine that sometimes the array a_issue.custom_field_values is empty (or old) but not nil
68
    #see http://www.redmine.org/issues/13119
69
    a_issue.reset_custom_values!
70
    a_issue.save_custom_field_values
71
    cu_fi_val = a_issue.custom_field_values.detect {|cfv| cfv.custom_field == a_custom_field}
72
    assert_not_nil(cu_fi_val,"Found the defect 13118!")  
73
    cu_fi_val.value = the_value
74
    a_issue.save
75
    return a_issue
76
  end
77
  
78
  def update_custom_value_in_issue_intern2(a_issue, a_custom_field, the_value)
79
    #against bug in redmine that sometimes the array a_issue.custom_field_values is empty (or old) but not nil
80
    #see http://www.redmine.org/issues/13119
81
    a_issue.reset_custom_values!
82
    a_issue.save_custom_field_values
83
    a_issue.custom_field_values={a_custom_field.id => the_value}
84
    a_issue.save_custom_field_values
85
    cu_fi_val = a_issue.custom_field_values.detect {|cfv| cfv.custom_field == a_custom_field}
86
    assert_not_nil(cu_fi_val,"Found the defect 13118!")  
87
    return a_issue
88
  end
89
   
90
end
(1-1/2)