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