##// END OF EJS Templates
Random test failures in #test_..._if_an_exception_is_raised with ruby1.8.7-p358 and sqlite3....
Jean-Philippe Lang -
r8927:2009a9ff2550
parent child
Show More
@@ -1,199 +1,201
1 1 require File.expand_path('../../test_helper', __FILE__)
2 2
3 3 class ProjectEnumerationsControllerTest < ActionController::TestCase
4 4 fixtures :projects, :trackers, :issue_statuses, :issues,
5 5 :enumerations, :users, :issue_categories,
6 6 :projects_trackers,
7 7 :roles,
8 8 :member_roles,
9 9 :members,
10 10 :enabled_modules,
11 11 :workflows,
12 12 :custom_fields, :custom_fields_projects,
13 13 :custom_fields_trackers, :custom_values,
14 14 :time_entries
15 15
16 self.use_transactional_fixtures = false
17
16 18 def setup
17 19 @request.session[:user_id] = nil
18 20 Setting.default_language = 'en'
19 21 end
20 22
21 23 def test_update_to_override_system_activities
22 24 @request.session[:user_id] = 2 # manager
23 25 billable_field = TimeEntryActivityCustomField.find_by_name("Billable")
24 26
25 27 put :update, :project_id => 1, :enumerations => {
26 28 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate
27 29 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value
28 30 "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value
29 31 "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes
30 32 }
31 33
32 34 assert_response :redirect
33 35 assert_redirected_to '/projects/ecookbook/settings/activities'
34 36
35 37 # Created project specific activities...
36 38 project = Project.find('ecookbook')
37 39
38 40 # ... Design
39 41 design = project.time_entry_activities.find_by_name("Design")
40 42 assert design, "Project activity not found"
41 43
42 44 assert_equal 9, design.parent_id # Relate to the system activity
43 45 assert_not_equal design.parent.id, design.id # Different records
44 46 assert_equal design.parent.name, design.name # Same name
45 47 assert !design.active?
46 48
47 49 # ... Development
48 50 development = project.time_entry_activities.find_by_name("Development")
49 51 assert development, "Project activity not found"
50 52
51 53 assert_equal 10, development.parent_id # Relate to the system activity
52 54 assert_not_equal development.parent.id, development.id # Different records
53 55 assert_equal development.parent.name, development.name # Same name
54 56 assert development.active?
55 57 assert_equal "0", development.custom_value_for(billable_field).value
56 58
57 59 # ... Inactive Activity
58 60 previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity")
59 61 assert previously_inactive, "Project activity not found"
60 62
61 63 assert_equal 14, previously_inactive.parent_id # Relate to the system activity
62 64 assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records
63 65 assert_equal previously_inactive.parent.name, previously_inactive.name # Same name
64 66 assert previously_inactive.active?
65 67 assert_equal "1", previously_inactive.custom_value_for(billable_field).value
66 68
67 69 # ... QA
68 70 assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
69 71 end
70 72
71 73 def test_update_will_update_project_specific_activities
72 74 @request.session[:user_id] = 2 # manager
73 75
74 76 project_activity = TimeEntryActivity.new({
75 77 :name => 'Project Specific',
76 78 :parent => TimeEntryActivity.find(:first),
77 79 :project => Project.find(1),
78 80 :active => true
79 81 })
80 82 assert project_activity.save
81 83 project_activity_two = TimeEntryActivity.new({
82 84 :name => 'Project Specific Two',
83 85 :parent => TimeEntryActivity.find(:last),
84 86 :project => Project.find(1),
85 87 :active => true
86 88 })
87 89 assert project_activity_two.save
88 90
89 91
90 92 put :update, :project_id => 1, :enumerations => {
91 93 project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate
92 94 project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate
93 95 }
94 96
95 97 assert_response :redirect
96 98 assert_redirected_to '/projects/ecookbook/settings/activities'
97 99
98 100 # Created project specific activities...
99 101 project = Project.find('ecookbook')
100 102 assert_equal 2, project.time_entry_activities.count
101 103
102 104 activity_one = project.time_entry_activities.find_by_name(project_activity.name)
103 105 assert activity_one, "Project activity not found"
104 106 assert_equal project_activity.id, activity_one.id
105 107 assert !activity_one.active?
106 108
107 109 activity_two = project.time_entry_activities.find_by_name(project_activity_two.name)
108 110 assert activity_two, "Project activity not found"
109 111 assert_equal project_activity_two.id, activity_two.id
110 112 assert !activity_two.active?
111 113 end
112 114
113 115 def test_update_when_creating_new_activities_will_convert_existing_data
114 116 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
115 117
116 118 @request.session[:user_id] = 2 # manager
117 119 put :update, :project_id => 1, :enumerations => {
118 120 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate
119 121 }
120 122 assert_response :redirect
121 123
122 124 # No more TimeEntries using the system activity
123 125 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities"
124 126 # All TimeEntries using project activity
125 127 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1)
126 128 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity"
127 129 end
128 130
129 131 def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
130 132 # TODO: Need to cause an exception on create but these tests
131 133 # aren't setup for mocking. Just create a record now so the
132 134 # second one is a dupicate
133 135 parent = TimeEntryActivity.find(9)
134 136 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true})
135 137 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
136 138
137 139 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
138 140 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
139 141
140 142 @request.session[:user_id] = 2 # manager
141 143 put :update, :project_id => 1, :enumerations => {
142 144 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
143 145 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
144 146 }
145 147 assert_response :redirect
146 148
147 149 # TimeEntries shouldn't have been reassigned on the failed record
148 150 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities"
149 151 # TimeEntries shouldn't have been reassigned on the saved record either
150 152 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
151 153 end
152 154
153 155 def test_destroy
154 156 @request.session[:user_id] = 2 # manager
155 157 project_activity = TimeEntryActivity.new({
156 158 :name => 'Project Specific',
157 159 :parent => TimeEntryActivity.find(:first),
158 160 :project => Project.find(1),
159 161 :active => true
160 162 })
161 163 assert project_activity.save
162 164 project_activity_two = TimeEntryActivity.new({
163 165 :name => 'Project Specific Two',
164 166 :parent => TimeEntryActivity.find(:last),
165 167 :project => Project.find(1),
166 168 :active => true
167 169 })
168 170 assert project_activity_two.save
169 171
170 172 delete :destroy, :project_id => 1
171 173 assert_response :redirect
172 174 assert_redirected_to '/projects/ecookbook/settings/activities'
173 175
174 176 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
175 177 assert_nil TimeEntryActivity.find_by_id(project_activity_two.id)
176 178 end
177 179
178 180 def test_destroy_should_reassign_time_entries_back_to_the_system_activity
179 181 @request.session[:user_id] = 2 # manager
180 182 project_activity = TimeEntryActivity.new({
181 183 :name => 'Project Specific Design',
182 184 :parent => TimeEntryActivity.find(9),
183 185 :project => Project.find(1),
184 186 :active => true
185 187 })
186 188 assert project_activity.save
187 189 assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9])
188 190 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size
189 191
190 192 delete :destroy, :project_id => 1
191 193 assert_response :redirect
192 194 assert_redirected_to '/projects/ecookbook/settings/activities'
193 195
194 196 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
195 197 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity"
196 198 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity"
197 199 end
198 200
199 201 end
General Comments 0
You need to be logged in to leave comments. Login now