##// END OF EJS Templates
add functional tests for bulk edit time entries (#7996)....
Toshi MARUYAMA -
r5195:c2baf187ac66
parent child
Show More
@@ -1,131 +1,145
1 ---
1 ---
2 custom_fields_001:
2 custom_fields_001:
3 name: Database
3 name: Database
4 min_length: 0
4 min_length: 0
5 regexp: ""
5 regexp: ""
6 is_for_all: true
6 is_for_all: true
7 is_filter: true
7 is_filter: true
8 type: IssueCustomField
8 type: IssueCustomField
9 max_length: 0
9 max_length: 0
10 possible_values:
10 possible_values:
11 - MySQL
11 - MySQL
12 - PostgreSQL
12 - PostgreSQL
13 - Oracle
13 - Oracle
14 id: 1
14 id: 1
15 is_required: false
15 is_required: false
16 field_format: list
16 field_format: list
17 default_value: ""
17 default_value: ""
18 editable: true
18 editable: true
19 custom_fields_002:
19 custom_fields_002:
20 name: Searchable field
20 name: Searchable field
21 min_length: 1
21 min_length: 1
22 regexp: ""
22 regexp: ""
23 is_for_all: true
23 is_for_all: true
24 type: IssueCustomField
24 type: IssueCustomField
25 max_length: 100
25 max_length: 100
26 possible_values: ""
26 possible_values: ""
27 id: 2
27 id: 2
28 is_required: false
28 is_required: false
29 field_format: string
29 field_format: string
30 searchable: true
30 searchable: true
31 default_value: "Default string"
31 default_value: "Default string"
32 editable: true
32 editable: true
33 custom_fields_003:
33 custom_fields_003:
34 name: Development status
34 name: Development status
35 min_length: 0
35 min_length: 0
36 regexp: ""
36 regexp: ""
37 is_for_all: false
37 is_for_all: false
38 is_filter: true
38 is_filter: true
39 type: ProjectCustomField
39 type: ProjectCustomField
40 max_length: 0
40 max_length: 0
41 possible_values:
41 possible_values:
42 - Stable
42 - Stable
43 - Beta
43 - Beta
44 - Alpha
44 - Alpha
45 - Planning
45 - Planning
46 id: 3
46 id: 3
47 is_required: false
47 is_required: false
48 field_format: list
48 field_format: list
49 default_value: ""
49 default_value: ""
50 editable: true
50 editable: true
51 custom_fields_004:
51 custom_fields_004:
52 name: Phone number
52 name: Phone number
53 min_length: 0
53 min_length: 0
54 regexp: ""
54 regexp: ""
55 is_for_all: false
55 is_for_all: false
56 type: UserCustomField
56 type: UserCustomField
57 max_length: 0
57 max_length: 0
58 possible_values: ""
58 possible_values: ""
59 id: 4
59 id: 4
60 is_required: false
60 is_required: false
61 field_format: string
61 field_format: string
62 default_value: ""
62 default_value: ""
63 editable: true
63 editable: true
64 custom_fields_005:
64 custom_fields_005:
65 name: Money
65 name: Money
66 min_length: 0
66 min_length: 0
67 regexp: ""
67 regexp: ""
68 is_for_all: false
68 is_for_all: false
69 type: UserCustomField
69 type: UserCustomField
70 max_length: 0
70 max_length: 0
71 possible_values: ""
71 possible_values: ""
72 id: 5
72 id: 5
73 is_required: false
73 is_required: false
74 field_format: float
74 field_format: float
75 default_value: ""
75 default_value: ""
76 editable: true
76 editable: true
77 custom_fields_006:
77 custom_fields_006:
78 name: Float field
78 name: Float field
79 min_length: 0
79 min_length: 0
80 regexp: ""
80 regexp: ""
81 is_for_all: true
81 is_for_all: true
82 type: IssueCustomField
82 type: IssueCustomField
83 max_length: 0
83 max_length: 0
84 possible_values: ""
84 possible_values: ""
85 id: 6
85 id: 6
86 is_required: false
86 is_required: false
87 field_format: float
87 field_format: float
88 default_value: ""
88 default_value: ""
89 editable: true
89 editable: true
90 custom_fields_007:
90 custom_fields_007:
91 name: Billable
91 name: Billable
92 min_length: 0
92 min_length: 0
93 regexp: ""
93 regexp: ""
94 is_for_all: false
94 is_for_all: false
95 is_filter: true
95 is_filter: true
96 type: TimeEntryActivityCustomField
96 type: TimeEntryActivityCustomField
97 max_length: 0
97 max_length: 0
98 possible_values: ""
98 possible_values: ""
99 id: 7
99 id: 7
100 is_required: false
100 is_required: false
101 field_format: bool
101 field_format: bool
102 default_value: ""
102 default_value: ""
103 editable: true
103 editable: true
104 custom_fields_008:
104 custom_fields_008:
105 name: Custom date
105 name: Custom date
106 min_length: 0
106 min_length: 0
107 regexp: ""
107 regexp: ""
108 is_for_all: true
108 is_for_all: true
109 is_filter: false
109 is_filter: false
110 type: IssueCustomField
110 type: IssueCustomField
111 max_length: 0
111 max_length: 0
112 possible_values: ""
112 possible_values: ""
113 id: 8
113 id: 8
114 is_required: false
114 is_required: false
115 field_format: date
115 field_format: date
116 default_value: ""
116 default_value: ""
117 editable: true
117 editable: true
118 custom_fields_009:
118 custom_fields_009:
119 name: Project 1 cf
119 name: Project 1 cf
120 min_length: 0
120 min_length: 0
121 regexp: ""
121 regexp: ""
122 is_for_all: false
122 is_for_all: false
123 is_filter: true
123 is_filter: true
124 type: IssueCustomField
124 type: IssueCustomField
125 max_length: 0
125 max_length: 0
126 possible_values: ""
126 possible_values: ""
127 id: 9
127 id: 9
128 is_required: false
128 is_required: false
129 field_format: date
129 field_format: date
130 default_value: ""
130 default_value: ""
131 editable: true
131 editable: true
132 custom_fields_010:
133 name: Overtime
134 min_length: 0
135 regexp: ""
136 is_for_all: false
137 is_filter: false
138 type: TimeEntryCustomField
139 max_length: 0
140 possible_values: ""
141 id: 10
142 is_required: false
143 field_format: bool
144 default_value: 0
145 editable: true
@@ -1,58 +1,72
1 ---
1 ---
2 time_entries_001:
2 time_entries_001:
3 created_on: 2007-03-23 12:54:18 +01:00
3 created_on: 2007-03-23 12:54:18 +01:00
4 tweek: 12
4 tweek: 12
5 tmonth: 3
5 tmonth: 3
6 project_id: 1
6 project_id: 1
7 comments: My hours
7 comments: My hours
8 updated_on: 2007-03-23 12:54:18 +01:00
8 updated_on: 2007-03-23 12:54:18 +01:00
9 activity_id: 9
9 activity_id: 9
10 spent_on: 2007-03-23
10 spent_on: 2007-03-23
11 issue_id: 1
11 issue_id: 1
12 id: 1
12 id: 1
13 hours: 4.25
13 hours: 4.25
14 user_id: 2
14 user_id: 2
15 tyear: 2007
15 tyear: 2007
16 time_entries_002:
16 time_entries_002:
17 created_on: 2007-03-23 14:11:04 +01:00
17 created_on: 2007-03-23 14:11:04 +01:00
18 tweek: 11
18 tweek: 11
19 tmonth: 3
19 tmonth: 3
20 project_id: 1
20 project_id: 1
21 comments: ""
21 comments: ""
22 updated_on: 2007-03-23 14:11:04 +01:00
22 updated_on: 2007-03-23 14:11:04 +01:00
23 activity_id: 9
23 activity_id: 9
24 spent_on: 2007-03-12
24 spent_on: 2007-03-12
25 issue_id: 1
25 issue_id: 1
26 id: 2
26 id: 2
27 hours: 150.0
27 hours: 150.0
28 user_id: 1
28 user_id: 1
29 tyear: 2007
29 tyear: 2007
30 time_entries_003:
30 time_entries_003:
31 created_on: 2007-04-21 12:20:48 +02:00
31 created_on: 2007-04-21 12:20:48 +02:00
32 tweek: 16
32 tweek: 16
33 tmonth: 4
33 tmonth: 4
34 project_id: 1
34 project_id: 1
35 comments: ""
35 comments: ""
36 updated_on: 2007-04-21 12:20:48 +02:00
36 updated_on: 2007-04-21 12:20:48 +02:00
37 activity_id: 9
37 activity_id: 9
38 spent_on: 2007-04-21
38 spent_on: 2007-04-21
39 issue_id: 3
39 issue_id: 3
40 id: 3
40 id: 3
41 hours: 1.0
41 hours: 1.0
42 user_id: 1
42 user_id: 1
43 tyear: 2007
43 tyear: 2007
44 time_entries_004:
44 time_entries_004:
45 created_on: 2007-04-22 12:20:48 +02:00
45 created_on: 2007-04-22 12:20:48 +02:00
46 tweek: 16
46 tweek: 16
47 tmonth: 4
47 tmonth: 4
48 project_id: 3
48 project_id: 3
49 comments: Time spent on a subproject
49 comments: Time spent on a subproject
50 updated_on: 2007-04-22 12:20:48 +02:00
50 updated_on: 2007-04-22 12:20:48 +02:00
51 activity_id: 10
51 activity_id: 10
52 spent_on: 2007-04-22
52 spent_on: 2007-04-22
53 issue_id:
53 issue_id:
54 id: 4
54 id: 4
55 hours: 7.65
55 hours: 7.65
56 user_id: 1
56 user_id: 1
57 tyear: 2007
57 tyear: 2007
58 time_entries_005:
59 created_on: 2011-03-22 12:20:48 +02:00
60 tweek: 12
61 tmonth: 3
62 project_id: 5
63 comments: Time spent on a subproject
64 updated_on: 2011-03-22 12:20:48 +02:00
65 activity_id: 10
66 spent_on: 2011-03-22
67 issue_id:
68 id: 5
69 hours: 7.65
70 user_id: 1
71 tyear: 2011
58
72
@@ -1,265 +1,336
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # redMine - project management software
2 # redMine - project management software
3 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 #
4 #
5 # This program is free software; you can redistribute it and/or
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
8 # of the License, or (at your option) any later version.
9 #
9 #
10 # This program is distributed in the hope that it will be useful,
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
13 # GNU General Public License for more details.
14 #
14 #
15 # You should have received a copy of the GNU General Public License
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
19 require File.expand_path('../../test_helper', __FILE__)
19 require File.expand_path('../../test_helper', __FILE__)
20 require 'timelog_controller'
20 require 'timelog_controller'
21
21
22 # Re-raise errors caught by the controller.
22 # Re-raise errors caught by the controller.
23 class TimelogController; def rescue_action(e) raise e end; end
23 class TimelogController; def rescue_action(e) raise e end; end
24
24
25 class TimelogControllerTest < ActionController::TestCase
25 class TimelogControllerTest < ActionController::TestCase
26 fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values
26 fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values
27
27
28 def setup
28 def setup
29 @controller = TimelogController.new
29 @controller = TimelogController.new
30 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
31 @response = ActionController::TestResponse.new
32 end
32 end
33
33
34 def test_get_new
34 def test_get_new
35 @request.session[:user_id] = 3
35 @request.session[:user_id] = 3
36 get :new, :project_id => 1
36 get :new, :project_id => 1
37 assert_response :success
37 assert_response :success
38 assert_template 'edit'
38 assert_template 'edit'
39 # Default activity selected
39 # Default activity selected
40 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
40 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
41 :content => 'Development'
41 :content => 'Development'
42 end
42 end
43
43
44 def test_get_new_should_only_show_active_time_entry_activities
44 def test_get_new_should_only_show_active_time_entry_activities
45 @request.session[:user_id] = 3
45 @request.session[:user_id] = 3
46 get :new, :project_id => 1
46 get :new, :project_id => 1
47 assert_response :success
47 assert_response :success
48 assert_template 'edit'
48 assert_template 'edit'
49 assert_no_tag :tag => 'option', :content => 'Inactive Activity'
49 assert_no_tag :tag => 'option', :content => 'Inactive Activity'
50
50
51 end
51 end
52
52
53 def test_get_edit_existing_time
53 def test_get_edit_existing_time
54 @request.session[:user_id] = 2
54 @request.session[:user_id] = 2
55 get :edit, :id => 2, :project_id => nil
55 get :edit, :id => 2, :project_id => nil
56 assert_response :success
56 assert_response :success
57 assert_template 'edit'
57 assert_template 'edit'
58 # Default activity selected
58 # Default activity selected
59 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
59 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
60 end
60 end
61
61
62 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
62 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
63 te = TimeEntry.find(1)
63 te = TimeEntry.find(1)
64 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
64 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
65 te.save!
65 te.save!
66
66
67 @request.session[:user_id] = 1
67 @request.session[:user_id] = 1
68 get :edit, :project_id => 1, :id => 1
68 get :edit, :project_id => 1, :id => 1
69 assert_response :success
69 assert_response :success
70 assert_template 'edit'
70 assert_template 'edit'
71 # Blank option since nothing is pre-selected
71 # Blank option since nothing is pre-selected
72 assert_tag :tag => 'option', :content => '--- Please select ---'
72 assert_tag :tag => 'option', :content => '--- Please select ---'
73 end
73 end
74
74
75 def test_post_create
75 def test_post_create
76 # TODO: should POST to issues’ time log instead of project. change form
76 # TODO: should POST to issues’ time log instead of project. change form
77 # and routing
77 # and routing
78 @request.session[:user_id] = 3
78 @request.session[:user_id] = 3
79 post :create, :project_id => 1,
79 post :create, :project_id => 1,
80 :time_entry => {:comments => 'Some work on TimelogControllerTest',
80 :time_entry => {:comments => 'Some work on TimelogControllerTest',
81 # Not the default activity
81 # Not the default activity
82 :activity_id => '11',
82 :activity_id => '11',
83 :spent_on => '2008-03-14',
83 :spent_on => '2008-03-14',
84 :issue_id => '1',
84 :issue_id => '1',
85 :hours => '7.3'}
85 :hours => '7.3'}
86 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
86 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
87
87
88 i = Issue.find(1)
88 i = Issue.find(1)
89 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
89 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
90 assert_not_nil t
90 assert_not_nil t
91 assert_equal 11, t.activity_id
91 assert_equal 11, t.activity_id
92 assert_equal 7.3, t.hours
92 assert_equal 7.3, t.hours
93 assert_equal 3, t.user_id
93 assert_equal 3, t.user_id
94 assert_equal i, t.issue
94 assert_equal i, t.issue
95 assert_equal i.project, t.project
95 assert_equal i.project, t.project
96 end
96 end
97
97
98 def test_post_create_with_blank_issue
98 def test_post_create_with_blank_issue
99 # TODO: should POST to issues’ time log instead of project. change form
99 # TODO: should POST to issues’ time log instead of project. change form
100 # and routing
100 # and routing
101 @request.session[:user_id] = 3
101 @request.session[:user_id] = 3
102 post :create, :project_id => 1,
102 post :create, :project_id => 1,
103 :time_entry => {:comments => 'Some work on TimelogControllerTest',
103 :time_entry => {:comments => 'Some work on TimelogControllerTest',
104 # Not the default activity
104 # Not the default activity
105 :activity_id => '11',
105 :activity_id => '11',
106 :issue_id => '',
106 :issue_id => '',
107 :spent_on => '2008-03-14',
107 :spent_on => '2008-03-14',
108 :hours => '7.3'}
108 :hours => '7.3'}
109 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
109 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
110
110
111 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
111 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
112 assert_not_nil t
112 assert_not_nil t
113 assert_equal 11, t.activity_id
113 assert_equal 11, t.activity_id
114 assert_equal 7.3, t.hours
114 assert_equal 7.3, t.hours
115 assert_equal 3, t.user_id
115 assert_equal 3, t.user_id
116 end
116 end
117
117
118 def test_update
118 def test_update
119 entry = TimeEntry.find(1)
119 entry = TimeEntry.find(1)
120 assert_equal 1, entry.issue_id
120 assert_equal 1, entry.issue_id
121 assert_equal 2, entry.user_id
121 assert_equal 2, entry.user_id
122
122
123 @request.session[:user_id] = 1
123 @request.session[:user_id] = 1
124 put :update, :id => 1,
124 put :update, :id => 1,
125 :time_entry => {:issue_id => '2',
125 :time_entry => {:issue_id => '2',
126 :hours => '8'}
126 :hours => '8'}
127 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
127 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
128 entry.reload
128 entry.reload
129
129
130 assert_equal 8, entry.hours
130 assert_equal 8, entry.hours
131 assert_equal 2, entry.issue_id
131 assert_equal 2, entry.issue_id
132 assert_equal 2, entry.user_id
132 assert_equal 2, entry.user_id
133 end
133 end
134
134
135 def test_get_bulk_edit
136 @request.session[:user_id] = 2
137 get :bulk_edit, :ids => [1, 2]
138 assert_response :success
139 assert_template 'bulk_edit'
140
141 # System wide custom field
142 assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'}
143 end
144
145 def test_get_bulk_edit_on_different_projects
146 @request.session[:user_id] = 2
147 get :bulk_edit, :ids => [1, 2, 6]
148 assert_response :success
149 assert_template 'bulk_edit'
150 end
151
152 def test_bulk_update
153 @request.session[:user_id] = 2
154 # update time entry activity
155 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
156
157 assert_response 302
158 # check that the issues were updated
159 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
160 end
161
162 def test_bulk_update_on_different_projects
163 @request.session[:user_id] = 2
164 # update time entry activity
165 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
166
167 assert_response 302
168 # check that the issues were updated
169 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
170 end
171
172 def test_bulk_update_on_different_projects_without_rights
173 @request.session[:user_id] = 3
174 user = User.find(3)
175 action = { :controller => "timelog", :action => "bulk_update" }
176 assert user.allowed_to?(action, TimeEntry.find(1).project)
177 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
178 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
179 assert_response 403
180 end
181
182 def test_bulk_update_custom_field
183 @request.session[:user_id] = 2
184 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
185
186 assert_response 302
187 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
188 end
189
190 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
191 @request.session[:user_id] = 2
192 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
193
194 assert_response :redirect
195 assert_redirected_to '/time_entries'
196 end
197
198 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
199 @request.session[:user_id] = 2
200 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
201
202 assert_response :redirect
203 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
204 end
205
135 def test_destroy
206 def test_destroy
136 @request.session[:user_id] = 2
207 @request.session[:user_id] = 2
137 delete :destroy, :id => 1
208 delete :destroy, :id => 1
138 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
209 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
139 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
210 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
140 assert_nil TimeEntry.find_by_id(1)
211 assert_nil TimeEntry.find_by_id(1)
141 end
212 end
142
213
143 def test_destroy_should_fail
214 def test_destroy_should_fail
144 # simulate that this fails (e.g. due to a plugin), see #5700
215 # simulate that this fails (e.g. due to a plugin), see #5700
145 TimeEntry.class_eval do
216 TimeEntry.class_eval do
146 before_destroy :stop_callback_chain
217 before_destroy :stop_callback_chain
147 def stop_callback_chain ; return false ; end
218 def stop_callback_chain ; return false ; end
148 end
219 end
149
220
150 @request.session[:user_id] = 2
221 @request.session[:user_id] = 2
151 delete :destroy, :id => 1
222 delete :destroy, :id => 1
152 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
223 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
153 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
224 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
154 assert_not_nil TimeEntry.find_by_id(1)
225 assert_not_nil TimeEntry.find_by_id(1)
155
226
156 # remove the simulation
227 # remove the simulation
157 TimeEntry.before_destroy.reject! {|callback| callback.method == :stop_callback_chain }
228 TimeEntry.before_destroy.reject! {|callback| callback.method == :stop_callback_chain }
158 end
229 end
159
230
160 def test_index_all_projects
231 def test_index_all_projects
161 get :index
232 get :index
162 assert_response :success
233 assert_response :success
163 assert_template 'index'
234 assert_template 'index'
164 assert_not_nil assigns(:total_hours)
235 assert_not_nil assigns(:total_hours)
165 assert_equal "162.90", "%.2f" % assigns(:total_hours)
236 assert_equal "162.90", "%.2f" % assigns(:total_hours)
166 assert_tag :form,
237 assert_tag :form,
167 :attributes => {:action => "/time_entries", :id => 'query_form'}
238 :attributes => {:action => "/time_entries", :id => 'query_form'}
168 end
239 end
169
240
170 def test_index_at_project_level
241 def test_index_at_project_level
171 get :index, :project_id => 'ecookbook'
242 get :index, :project_id => 'ecookbook'
172 assert_response :success
243 assert_response :success
173 assert_template 'index'
244 assert_template 'index'
174 assert_not_nil assigns(:entries)
245 assert_not_nil assigns(:entries)
175 assert_equal 4, assigns(:entries).size
246 assert_equal 4, assigns(:entries).size
176 # project and subproject
247 # project and subproject
177 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
248 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
178 assert_not_nil assigns(:total_hours)
249 assert_not_nil assigns(:total_hours)
179 assert_equal "162.90", "%.2f" % assigns(:total_hours)
250 assert_equal "162.90", "%.2f" % assigns(:total_hours)
180 # display all time by default
251 # display all time by default
181 assert_equal '2007-03-12'.to_date, assigns(:from)
252 assert_equal '2007-03-12'.to_date, assigns(:from)
182 assert_equal '2007-04-22'.to_date, assigns(:to)
253 assert_equal '2007-04-22'.to_date, assigns(:to)
183 assert_tag :form,
254 assert_tag :form,
184 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
255 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
185 end
256 end
186
257
187 def test_index_at_project_level_with_date_range
258 def test_index_at_project_level_with_date_range
188 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
259 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
189 assert_response :success
260 assert_response :success
190 assert_template 'index'
261 assert_template 'index'
191 assert_not_nil assigns(:entries)
262 assert_not_nil assigns(:entries)
192 assert_equal 3, assigns(:entries).size
263 assert_equal 3, assigns(:entries).size
193 assert_not_nil assigns(:total_hours)
264 assert_not_nil assigns(:total_hours)
194 assert_equal "12.90", "%.2f" % assigns(:total_hours)
265 assert_equal "12.90", "%.2f" % assigns(:total_hours)
195 assert_equal '2007-03-20'.to_date, assigns(:from)
266 assert_equal '2007-03-20'.to_date, assigns(:from)
196 assert_equal '2007-04-30'.to_date, assigns(:to)
267 assert_equal '2007-04-30'.to_date, assigns(:to)
197 assert_tag :form,
268 assert_tag :form,
198 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
269 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
199 end
270 end
200
271
201 def test_index_at_project_level_with_period
272 def test_index_at_project_level_with_period
202 get :index, :project_id => 'ecookbook', :period => '7_days'
273 get :index, :project_id => 'ecookbook', :period => '7_days'
203 assert_response :success
274 assert_response :success
204 assert_template 'index'
275 assert_template 'index'
205 assert_not_nil assigns(:entries)
276 assert_not_nil assigns(:entries)
206 assert_not_nil assigns(:total_hours)
277 assert_not_nil assigns(:total_hours)
207 assert_equal Date.today - 7, assigns(:from)
278 assert_equal Date.today - 7, assigns(:from)
208 assert_equal Date.today, assigns(:to)
279 assert_equal Date.today, assigns(:to)
209 assert_tag :form,
280 assert_tag :form,
210 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
281 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
211 end
282 end
212
283
213 def test_index_one_day
284 def test_index_one_day
214 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23"
285 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23"
215 assert_response :success
286 assert_response :success
216 assert_template 'index'
287 assert_template 'index'
217 assert_not_nil assigns(:total_hours)
288 assert_not_nil assigns(:total_hours)
218 assert_equal "4.25", "%.2f" % assigns(:total_hours)
289 assert_equal "4.25", "%.2f" % assigns(:total_hours)
219 assert_tag :form,
290 assert_tag :form,
220 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
291 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
221 end
292 end
222
293
223 def test_index_at_issue_level
294 def test_index_at_issue_level
224 get :index, :issue_id => 1
295 get :index, :issue_id => 1
225 assert_response :success
296 assert_response :success
226 assert_template 'index'
297 assert_template 'index'
227 assert_not_nil assigns(:entries)
298 assert_not_nil assigns(:entries)
228 assert_equal 2, assigns(:entries).size
299 assert_equal 2, assigns(:entries).size
229 assert_not_nil assigns(:total_hours)
300 assert_not_nil assigns(:total_hours)
230 assert_equal 154.25, assigns(:total_hours)
301 assert_equal 154.25, assigns(:total_hours)
231 # display all time based on what's been logged
302 # display all time based on what's been logged
232 assert_equal '2007-03-12'.to_date, assigns(:from)
303 assert_equal '2007-03-12'.to_date, assigns(:from)
233 assert_equal '2007-04-22'.to_date, assigns(:to)
304 assert_equal '2007-04-22'.to_date, assigns(:to)
234 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
305 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
235 # to use /issues/:issue_id/time_entries
306 # to use /issues/:issue_id/time_entries
236 assert_tag :form,
307 assert_tag :form,
237 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
308 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
238 end
309 end
239
310
240 def test_index_atom_feed
311 def test_index_atom_feed
241 get :index, :project_id => 1, :format => 'atom'
312 get :index, :project_id => 1, :format => 'atom'
242 assert_response :success
313 assert_response :success
243 assert_equal 'application/atom+xml', @response.content_type
314 assert_equal 'application/atom+xml', @response.content_type
244 assert_not_nil assigns(:items)
315 assert_not_nil assigns(:items)
245 assert assigns(:items).first.is_a?(TimeEntry)
316 assert assigns(:items).first.is_a?(TimeEntry)
246 end
317 end
247
318
248 def test_index_all_projects_csv_export
319 def test_index_all_projects_csv_export
249 Setting.date_format = '%m/%d/%Y'
320 Setting.date_format = '%m/%d/%Y'
250 get :index, :format => 'csv'
321 get :index, :format => 'csv'
251 assert_response :success
322 assert_response :success
252 assert_equal 'text/csv', @response.content_type
323 assert_equal 'text/csv', @response.content_type
253 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
324 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
254 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
325 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
255 end
326 end
256
327
257 def test_index_csv_export
328 def test_index_csv_export
258 Setting.date_format = '%m/%d/%Y'
329 Setting.date_format = '%m/%d/%Y'
259 get :index, :project_id => 1, :format => 'csv'
330 get :index, :project_id => 1, :format => 'csv'
260 assert_response :success
331 assert_response :success
261 assert_equal 'text/csv', @response.content_type
332 assert_equal 'text/csv', @response.content_type
262 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
333 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
263 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
334 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
264 end
335 end
265 end
336 end
@@ -1,85 +1,85
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class TimeEntryActivityTest < ActiveSupport::TestCase
20 class TimeEntryActivityTest < ActiveSupport::TestCase
21 fixtures :enumerations, :time_entries
21 fixtures :enumerations, :time_entries
22
22
23 def test_should_be_an_enumeration
23 def test_should_be_an_enumeration
24 assert TimeEntryActivity.ancestors.include?(Enumeration)
24 assert TimeEntryActivity.ancestors.include?(Enumeration)
25 end
25 end
26
26
27 def test_objects_count
27 def test_objects_count
28 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
28 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
29 assert_equal 1, TimeEntryActivity.find_by_name("Development").objects_count
29 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
30 end
30 end
31
31
32 def test_option_name
32 def test_option_name
33 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
33 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
34 end
34 end
35
35
36 def test_create_with_custom_field
36 def test_create_with_custom_field
37 field = TimeEntryActivityCustomField.find_by_name('Billable')
37 field = TimeEntryActivityCustomField.find_by_name('Billable')
38 e = TimeEntryActivity.new(:name => 'Custom Data')
38 e = TimeEntryActivity.new(:name => 'Custom Data')
39 e.custom_field_values = {field.id => "1"}
39 e.custom_field_values = {field.id => "1"}
40 assert e.save
40 assert e.save
41
41
42 e.reload
42 e.reload
43 assert_equal "1", e.custom_value_for(field).value
43 assert_equal "1", e.custom_value_for(field).value
44 end
44 end
45
45
46 def test_create_without_required_custom_field_should_fail
46 def test_create_without_required_custom_field_should_fail
47 field = TimeEntryActivityCustomField.find_by_name('Billable')
47 field = TimeEntryActivityCustomField.find_by_name('Billable')
48 field.update_attribute(:is_required, true)
48 field.update_attribute(:is_required, true)
49
49
50 e = TimeEntryActivity.new(:name => 'Custom Data')
50 e = TimeEntryActivity.new(:name => 'Custom Data')
51 assert !e.save
51 assert !e.save
52 assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
52 assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
53 end
53 end
54
54
55 def test_create_with_required_custom_field_should_succeed
55 def test_create_with_required_custom_field_should_succeed
56 field = TimeEntryActivityCustomField.find_by_name('Billable')
56 field = TimeEntryActivityCustomField.find_by_name('Billable')
57 field.update_attribute(:is_required, true)
57 field.update_attribute(:is_required, true)
58
58
59 e = TimeEntryActivity.new(:name => 'Custom Data')
59 e = TimeEntryActivity.new(:name => 'Custom Data')
60 e.custom_field_values = {field.id => "1"}
60 e.custom_field_values = {field.id => "1"}
61 assert e.save
61 assert e.save
62 end
62 end
63
63
64 def test_update_issue_with_required_custom_field_change
64 def test_update_issue_with_required_custom_field_change
65 field = TimeEntryActivityCustomField.find_by_name('Billable')
65 field = TimeEntryActivityCustomField.find_by_name('Billable')
66 field.update_attribute(:is_required, true)
66 field.update_attribute(:is_required, true)
67
67
68 e = TimeEntryActivity.find(10)
68 e = TimeEntryActivity.find(10)
69 assert e.available_custom_fields.include?(field)
69 assert e.available_custom_fields.include?(field)
70 # No change to custom field, record can be saved
70 # No change to custom field, record can be saved
71 assert e.save
71 assert e.save
72 # Blanking custom field, save should fail
72 # Blanking custom field, save should fail
73 e.custom_field_values = {field.id => ""}
73 e.custom_field_values = {field.id => ""}
74 assert !e.save
74 assert !e.save
75 assert e.errors.on(:custom_values)
75 assert e.errors.on(:custom_values)
76
76
77 # Update custom field to valid value, save should succeed
77 # Update custom field to valid value, save should succeed
78 e.custom_field_values = {field.id => "0"}
78 e.custom_field_values = {field.id => "0"}
79 assert e.save
79 assert e.save
80 e.reload
80 e.reload
81 assert_equal "0", e.custom_value_for(field).value
81 assert_equal "0", e.custom_value_for(field).value
82 end
82 end
83
83
84 end
84 end
85
85
General Comments 0
You need to be logged in to leave comments. Login now