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