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