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