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