@@ -1,21 +1,21 | |||||
1 | <h2><%= l(:label_spent_time) %></h2> |
|
1 | <h2><%= l(:label_spent_time) %></h2> | |
2 |
|
2 | |||
3 | <% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => 'edit', :project_id => @time_entry.project} do |f| %> |
|
3 | <% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => 'edit', :id => @time_entry, :project_id => @time_entry.project} do |f| %> | |
4 | <%= error_messages_for 'time_entry' %> |
|
4 | <%= error_messages_for 'time_entry' %> | |
5 | <%= back_url_hidden_field_tag %> |
|
5 | <%= back_url_hidden_field_tag %> | |
6 |
|
6 | |||
7 | <div class="box"> |
|
7 | <div class="box"> | |
8 | <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p> |
|
8 | <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p> | |
9 | <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p> |
|
9 | <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p> | |
10 | <p><%= f.text_field :hours, :size => 6, :required => true %></p> |
|
10 | <p><%= f.text_field :hours, :size => 6, :required => true %></p> | |
11 | <p><%= f.text_field :comments, :size => 100 %></p> |
|
11 | <p><%= f.text_field :comments, :size => 100 %></p> | |
12 | <p><%= f.select :activity_id, activity_collection_for_select_options, :required => true %></p> |
|
12 | <p><%= f.select :activity_id, activity_collection_for_select_options, :required => true %></p> | |
13 | <% @time_entry.custom_field_values.each do |value| %> |
|
13 | <% @time_entry.custom_field_values.each do |value| %> | |
14 | <p><%= custom_field_tag_with_label :time_entry, value %></p> |
|
14 | <p><%= custom_field_tag_with_label :time_entry, value %></p> | |
15 | <% end %> |
|
15 | <% end %> | |
16 | <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %> |
|
16 | <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %> | |
17 | </div> |
|
17 | </div> | |
18 |
|
18 | |||
19 | <%= submit_tag l(:button_save) %> |
|
19 | <%= submit_tag l(:button_save) %> | |
20 |
|
20 | |||
21 | <% end %> |
|
21 | <% end %> |
@@ -1,385 +1,394 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'timelog_controller' |
|
19 | require 'timelog_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class TimelogController; def rescue_action(e) raise e end; end |
|
22 | class TimelogController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class TimelogControllerTest < Test::Unit::TestCase |
|
24 | class TimelogControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values |
|
25 | fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = TimelogController.new |
|
28 | @controller = TimelogController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_edit_routing |
|
33 | def test_edit_routing | |
34 | assert_routing( |
|
34 | assert_routing( | |
35 | {:method => :get, :path => '/issues/567/time_entries/new'}, |
|
35 | {:method => :get, :path => '/issues/567/time_entries/new'}, | |
36 | :controller => 'timelog', :action => 'edit', :issue_id => '567' |
|
36 | :controller => 'timelog', :action => 'edit', :issue_id => '567' | |
37 | ) |
|
37 | ) | |
38 | assert_routing( |
|
38 | assert_routing( | |
39 | {:method => :get, :path => '/projects/ecookbook/time_entries/new'}, |
|
39 | {:method => :get, :path => '/projects/ecookbook/time_entries/new'}, | |
40 | :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook' |
|
40 | :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook' | |
41 | ) |
|
41 | ) | |
42 | assert_routing( |
|
42 | assert_routing( | |
43 | {:method => :get, :path => '/projects/ecookbook/issues/567/time_entries/new'}, |
|
43 | {:method => :get, :path => '/projects/ecookbook/issues/567/time_entries/new'}, | |
44 | :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook', :issue_id => '567' |
|
44 | :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook', :issue_id => '567' | |
45 | ) |
|
45 | ) | |
46 |
|
46 | |||
47 | #TODO: change new form to POST to issue_time_entries_path instead of to edit action |
|
47 | #TODO: change new form to POST to issue_time_entries_path instead of to edit action | |
48 | #TODO: change edit form to PUT to time_entry_path |
|
48 | #TODO: change edit form to PUT to time_entry_path | |
49 | assert_routing( |
|
49 | assert_routing( | |
50 | {:method => :get, :path => '/time_entries/22/edit'}, |
|
50 | {:method => :get, :path => '/time_entries/22/edit'}, | |
51 | :controller => 'timelog', :action => 'edit', :id => '22' |
|
51 | :controller => 'timelog', :action => 'edit', :id => '22' | |
52 | ) |
|
52 | ) | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_get_edit |
|
55 | def test_get_edit | |
56 | @request.session[:user_id] = 3 |
|
56 | @request.session[:user_id] = 3 | |
57 | get :edit, :project_id => 1 |
|
57 | get :edit, :project_id => 1 | |
58 | assert_response :success |
|
58 | assert_response :success | |
59 | assert_template 'edit' |
|
59 | assert_template 'edit' | |
60 | # Default activity selected |
|
60 | # Default activity selected | |
61 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, |
|
61 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, | |
62 | :content => 'Development' |
|
62 | :content => 'Development' | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
|
65 | def test_get_edit_existing_time | |||
|
66 | @request.session[:user_id] = 2 | |||
|
67 | get :edit, :id => 2, :project_id => nil | |||
|
68 | assert_response :success | |||
|
69 | assert_template 'edit' | |||
|
70 | # Default activity selected | |||
|
71 | assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/edit/2' } | |||
|
72 | end | |||
|
73 | ||||
65 | def test_post_edit |
|
74 | def test_post_edit | |
66 | # TODO: should POST to issuesβ time log instead of project. change form |
|
75 | # TODO: should POST to issuesβ time log instead of project. change form | |
67 | # and routing |
|
76 | # and routing | |
68 | @request.session[:user_id] = 3 |
|
77 | @request.session[:user_id] = 3 | |
69 | post :edit, :project_id => 1, |
|
78 | post :edit, :project_id => 1, | |
70 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
79 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
71 | # Not the default activity |
|
80 | # Not the default activity | |
72 | :activity_id => '11', |
|
81 | :activity_id => '11', | |
73 | :spent_on => '2008-03-14', |
|
82 | :spent_on => '2008-03-14', | |
74 | :issue_id => '1', |
|
83 | :issue_id => '1', | |
75 | :hours => '7.3'} |
|
84 | :hours => '7.3'} | |
76 | assert_redirected_to :action => 'details', :project_id => 'ecookbook' |
|
85 | assert_redirected_to :action => 'details', :project_id => 'ecookbook' | |
77 |
|
86 | |||
78 | i = Issue.find(1) |
|
87 | i = Issue.find(1) | |
79 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
88 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') | |
80 | assert_not_nil t |
|
89 | assert_not_nil t | |
81 | assert_equal 11, t.activity_id |
|
90 | assert_equal 11, t.activity_id | |
82 | assert_equal 7.3, t.hours |
|
91 | assert_equal 7.3, t.hours | |
83 | assert_equal 3, t.user_id |
|
92 | assert_equal 3, t.user_id | |
84 | assert_equal i, t.issue |
|
93 | assert_equal i, t.issue | |
85 | assert_equal i.project, t.project |
|
94 | assert_equal i.project, t.project | |
86 | end |
|
95 | end | |
87 |
|
96 | |||
88 | def test_update |
|
97 | def test_update | |
89 | entry = TimeEntry.find(1) |
|
98 | entry = TimeEntry.find(1) | |
90 | assert_equal 1, entry.issue_id |
|
99 | assert_equal 1, entry.issue_id | |
91 | assert_equal 2, entry.user_id |
|
100 | assert_equal 2, entry.user_id | |
92 |
|
101 | |||
93 | @request.session[:user_id] = 1 |
|
102 | @request.session[:user_id] = 1 | |
94 | post :edit, :id => 1, |
|
103 | post :edit, :id => 1, | |
95 | :time_entry => {:issue_id => '2', |
|
104 | :time_entry => {:issue_id => '2', | |
96 | :hours => '8'} |
|
105 | :hours => '8'} | |
97 | assert_redirected_to :action => 'details', :project_id => 'ecookbook' |
|
106 | assert_redirected_to :action => 'details', :project_id => 'ecookbook' | |
98 | entry.reload |
|
107 | entry.reload | |
99 |
|
108 | |||
100 | assert_equal 8, entry.hours |
|
109 | assert_equal 8, entry.hours | |
101 | assert_equal 2, entry.issue_id |
|
110 | assert_equal 2, entry.issue_id | |
102 | assert_equal 2, entry.user_id |
|
111 | assert_equal 2, entry.user_id | |
103 | end |
|
112 | end | |
104 |
|
113 | |||
105 | def test_destroy_routing |
|
114 | def test_destroy_routing | |
106 | #TODO: use DELETE to time_entry_path |
|
115 | #TODO: use DELETE to time_entry_path | |
107 | assert_routing( |
|
116 | assert_routing( | |
108 | {:method => :post, :path => '/time_entries/55/destroy'}, |
|
117 | {:method => :post, :path => '/time_entries/55/destroy'}, | |
109 | :controller => 'timelog', :action => 'destroy', :id => '55' |
|
118 | :controller => 'timelog', :action => 'destroy', :id => '55' | |
110 | ) |
|
119 | ) | |
111 | end |
|
120 | end | |
112 |
|
121 | |||
113 | def test_destroy |
|
122 | def test_destroy | |
114 | @request.session[:user_id] = 2 |
|
123 | @request.session[:user_id] = 2 | |
115 | post :destroy, :id => 1 |
|
124 | post :destroy, :id => 1 | |
116 | assert_redirected_to :action => 'details', :project_id => 'ecookbook' |
|
125 | assert_redirected_to :action => 'details', :project_id => 'ecookbook' | |
117 | assert_nil TimeEntry.find_by_id(1) |
|
126 | assert_nil TimeEntry.find_by_id(1) | |
118 | end |
|
127 | end | |
119 |
|
128 | |||
120 | def test_report_routing |
|
129 | def test_report_routing | |
121 | assert_routing( |
|
130 | assert_routing( | |
122 | {:method => :get, :path => '/projects/567/time_entries/report'}, |
|
131 | {:method => :get, :path => '/projects/567/time_entries/report'}, | |
123 | :controller => 'timelog', :action => 'report', :project_id => '567' |
|
132 | :controller => 'timelog', :action => 'report', :project_id => '567' | |
124 | ) |
|
133 | ) | |
125 | assert_routing( |
|
134 | assert_routing( | |
126 | {:method => :get, :path => '/projects/567/time_entries/report.csv'}, |
|
135 | {:method => :get, :path => '/projects/567/time_entries/report.csv'}, | |
127 | :controller => 'timelog', :action => 'report', :project_id => '567', :format => 'csv' |
|
136 | :controller => 'timelog', :action => 'report', :project_id => '567', :format => 'csv' | |
128 | ) |
|
137 | ) | |
129 | end |
|
138 | end | |
130 |
|
139 | |||
131 | def test_report_no_criteria |
|
140 | def test_report_no_criteria | |
132 | get :report, :project_id => 1 |
|
141 | get :report, :project_id => 1 | |
133 | assert_response :success |
|
142 | assert_response :success | |
134 | assert_template 'report' |
|
143 | assert_template 'report' | |
135 | end |
|
144 | end | |
136 |
|
145 | |||
137 | def test_report_routing_for_all_projects |
|
146 | def test_report_routing_for_all_projects | |
138 | assert_routing( |
|
147 | assert_routing( | |
139 | {:method => :get, :path => '/time_entries/report'}, |
|
148 | {:method => :get, :path => '/time_entries/report'}, | |
140 | :controller => 'timelog', :action => 'report' |
|
149 | :controller => 'timelog', :action => 'report' | |
141 | ) |
|
150 | ) | |
142 | end |
|
151 | end | |
143 |
|
152 | |||
144 | def test_report_all_projects |
|
153 | def test_report_all_projects | |
145 | get :report |
|
154 | get :report | |
146 | assert_response :success |
|
155 | assert_response :success | |
147 | assert_template 'report' |
|
156 | assert_template 'report' | |
148 | end |
|
157 | end | |
149 |
|
158 | |||
150 | def test_report_all_projects_denied |
|
159 | def test_report_all_projects_denied | |
151 | r = Role.anonymous |
|
160 | r = Role.anonymous | |
152 | r.permissions.delete(:view_time_entries) |
|
161 | r.permissions.delete(:view_time_entries) | |
153 | r.permissions_will_change! |
|
162 | r.permissions_will_change! | |
154 | r.save |
|
163 | r.save | |
155 | get :report |
|
164 | get :report | |
156 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' |
|
165 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' | |
157 | end |
|
166 | end | |
158 |
|
167 | |||
159 | def test_report_all_projects_one_criteria |
|
168 | def test_report_all_projects_one_criteria | |
160 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] |
|
169 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
161 | assert_response :success |
|
170 | assert_response :success | |
162 | assert_template 'report' |
|
171 | assert_template 'report' | |
163 | assert_not_nil assigns(:total_hours) |
|
172 | assert_not_nil assigns(:total_hours) | |
164 | assert_equal "8.65", "%.2f" % assigns(:total_hours) |
|
173 | assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
165 | end |
|
174 | end | |
166 |
|
175 | |||
167 | def test_report_all_time |
|
176 | def test_report_all_time | |
168 | get :report, :project_id => 1, :criterias => ['project', 'issue'] |
|
177 | get :report, :project_id => 1, :criterias => ['project', 'issue'] | |
169 | assert_response :success |
|
178 | assert_response :success | |
170 | assert_template 'report' |
|
179 | assert_template 'report' | |
171 | assert_not_nil assigns(:total_hours) |
|
180 | assert_not_nil assigns(:total_hours) | |
172 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
181 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
173 | end |
|
182 | end | |
174 |
|
183 | |||
175 | def test_report_all_time_by_day |
|
184 | def test_report_all_time_by_day | |
176 | get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day' |
|
185 | get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day' | |
177 | assert_response :success |
|
186 | assert_response :success | |
178 | assert_template 'report' |
|
187 | assert_template 'report' | |
179 | assert_not_nil assigns(:total_hours) |
|
188 | assert_not_nil assigns(:total_hours) | |
180 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
189 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
181 | assert_tag :tag => 'th', :content => '2007-03-12' |
|
190 | assert_tag :tag => 'th', :content => '2007-03-12' | |
182 | end |
|
191 | end | |
183 |
|
192 | |||
184 | def test_report_one_criteria |
|
193 | def test_report_one_criteria | |
185 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] |
|
194 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
186 | assert_response :success |
|
195 | assert_response :success | |
187 | assert_template 'report' |
|
196 | assert_template 'report' | |
188 | assert_not_nil assigns(:total_hours) |
|
197 | assert_not_nil assigns(:total_hours) | |
189 | assert_equal "8.65", "%.2f" % assigns(:total_hours) |
|
198 | assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
190 | end |
|
199 | end | |
191 |
|
200 | |||
192 | def test_report_two_criterias |
|
201 | def test_report_two_criterias | |
193 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] |
|
202 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
194 | assert_response :success |
|
203 | assert_response :success | |
195 | assert_template 'report' |
|
204 | assert_template 'report' | |
196 | assert_not_nil assigns(:total_hours) |
|
205 | assert_not_nil assigns(:total_hours) | |
197 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
206 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
198 | end |
|
207 | end | |
199 |
|
208 | |||
200 | def test_report_custom_field_criteria |
|
209 | def test_report_custom_field_criteria | |
201 | get :report, :project_id => 1, :criterias => ['project', 'cf_1'] |
|
210 | get :report, :project_id => 1, :criterias => ['project', 'cf_1'] | |
202 | assert_response :success |
|
211 | assert_response :success | |
203 | assert_template 'report' |
|
212 | assert_template 'report' | |
204 | assert_not_nil assigns(:total_hours) |
|
213 | assert_not_nil assigns(:total_hours) | |
205 | assert_not_nil assigns(:criterias) |
|
214 | assert_not_nil assigns(:criterias) | |
206 | assert_equal 2, assigns(:criterias).size |
|
215 | assert_equal 2, assigns(:criterias).size | |
207 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
216 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
208 | # Custom field column |
|
217 | # Custom field column | |
209 | assert_tag :tag => 'th', :content => 'Database' |
|
218 | assert_tag :tag => 'th', :content => 'Database' | |
210 | # Custom field row |
|
219 | # Custom field row | |
211 | assert_tag :tag => 'td', :content => 'MySQL', |
|
220 | assert_tag :tag => 'td', :content => 'MySQL', | |
212 | :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, |
|
221 | :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, | |
213 | :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, |
|
222 | :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, | |
214 | :content => '1' }} |
|
223 | :content => '1' }} | |
215 | end |
|
224 | end | |
216 |
|
225 | |||
217 | def test_report_one_criteria_no_result |
|
226 | def test_report_one_criteria_no_result | |
218 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] |
|
227 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] | |
219 | assert_response :success |
|
228 | assert_response :success | |
220 | assert_template 'report' |
|
229 | assert_template 'report' | |
221 | assert_not_nil assigns(:total_hours) |
|
230 | assert_not_nil assigns(:total_hours) | |
222 | assert_equal "0.00", "%.2f" % assigns(:total_hours) |
|
231 | assert_equal "0.00", "%.2f" % assigns(:total_hours) | |
223 | end |
|
232 | end | |
224 |
|
233 | |||
225 | def test_report_all_projects_csv_export |
|
234 | def test_report_all_projects_csv_export | |
226 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" |
|
235 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" | |
227 | assert_response :success |
|
236 | assert_response :success | |
228 | assert_equal 'text/csv', @response.content_type |
|
237 | assert_equal 'text/csv', @response.content_type | |
229 | lines = @response.body.chomp.split("\n") |
|
238 | lines = @response.body.chomp.split("\n") | |
230 | # Headers |
|
239 | # Headers | |
231 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first |
|
240 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first | |
232 | # Total row |
|
241 | # Total row | |
233 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last |
|
242 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
234 | end |
|
243 | end | |
235 |
|
244 | |||
236 | def test_report_csv_export |
|
245 | def test_report_csv_export | |
237 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" |
|
246 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" | |
238 | assert_response :success |
|
247 | assert_response :success | |
239 | assert_equal 'text/csv', @response.content_type |
|
248 | assert_equal 'text/csv', @response.content_type | |
240 | lines = @response.body.chomp.split("\n") |
|
249 | lines = @response.body.chomp.split("\n") | |
241 | # Headers |
|
250 | # Headers | |
242 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first |
|
251 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first | |
243 | # Total row |
|
252 | # Total row | |
244 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last |
|
253 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
245 | end |
|
254 | end | |
246 |
|
255 | |||
247 | def test_details_all_projects |
|
256 | def test_details_all_projects | |
248 | get :details |
|
257 | get :details | |
249 | assert_response :success |
|
258 | assert_response :success | |
250 | assert_template 'details' |
|
259 | assert_template 'details' | |
251 | assert_not_nil assigns(:total_hours) |
|
260 | assert_not_nil assigns(:total_hours) | |
252 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
261 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
253 | end |
|
262 | end | |
254 |
|
263 | |||
255 | def test_project_details_routing |
|
264 | def test_project_details_routing | |
256 | assert_routing( |
|
265 | assert_routing( | |
257 | {:method => :get, :path => '/projects/567/time_entries'}, |
|
266 | {:method => :get, :path => '/projects/567/time_entries'}, | |
258 | :controller => 'timelog', :action => 'details', :project_id => '567' |
|
267 | :controller => 'timelog', :action => 'details', :project_id => '567' | |
259 | ) |
|
268 | ) | |
260 | end |
|
269 | end | |
261 |
|
270 | |||
262 | def test_details_at_project_level |
|
271 | def test_details_at_project_level | |
263 | get :details, :project_id => 1 |
|
272 | get :details, :project_id => 1 | |
264 | assert_response :success |
|
273 | assert_response :success | |
265 | assert_template 'details' |
|
274 | assert_template 'details' | |
266 | assert_not_nil assigns(:entries) |
|
275 | assert_not_nil assigns(:entries) | |
267 | assert_equal 4, assigns(:entries).size |
|
276 | assert_equal 4, assigns(:entries).size | |
268 | # project and subproject |
|
277 | # project and subproject | |
269 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
|
278 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort | |
270 | assert_not_nil assigns(:total_hours) |
|
279 | assert_not_nil assigns(:total_hours) | |
271 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
280 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
272 | # display all time by default |
|
281 | # display all time by default | |
273 | assert_equal '2007-03-11'.to_date, assigns(:from) |
|
282 | assert_equal '2007-03-11'.to_date, assigns(:from) | |
274 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
283 | assert_equal '2007-04-22'.to_date, assigns(:to) | |
275 | end |
|
284 | end | |
276 |
|
285 | |||
277 | def test_details_at_project_level_with_date_range |
|
286 | def test_details_at_project_level_with_date_range | |
278 | get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30' |
|
287 | get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30' | |
279 | assert_response :success |
|
288 | assert_response :success | |
280 | assert_template 'details' |
|
289 | assert_template 'details' | |
281 | assert_not_nil assigns(:entries) |
|
290 | assert_not_nil assigns(:entries) | |
282 | assert_equal 3, assigns(:entries).size |
|
291 | assert_equal 3, assigns(:entries).size | |
283 | assert_not_nil assigns(:total_hours) |
|
292 | assert_not_nil assigns(:total_hours) | |
284 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
293 | assert_equal "12.90", "%.2f" % assigns(:total_hours) | |
285 | assert_equal '2007-03-20'.to_date, assigns(:from) |
|
294 | assert_equal '2007-03-20'.to_date, assigns(:from) | |
286 | assert_equal '2007-04-30'.to_date, assigns(:to) |
|
295 | assert_equal '2007-04-30'.to_date, assigns(:to) | |
287 | end |
|
296 | end | |
288 |
|
297 | |||
289 | def test_details_at_project_level_with_period |
|
298 | def test_details_at_project_level_with_period | |
290 | get :details, :project_id => 1, :period => '7_days' |
|
299 | get :details, :project_id => 1, :period => '7_days' | |
291 | assert_response :success |
|
300 | assert_response :success | |
292 | assert_template 'details' |
|
301 | assert_template 'details' | |
293 | assert_not_nil assigns(:entries) |
|
302 | assert_not_nil assigns(:entries) | |
294 | assert_not_nil assigns(:total_hours) |
|
303 | assert_not_nil assigns(:total_hours) | |
295 | assert_equal Date.today - 7, assigns(:from) |
|
304 | assert_equal Date.today - 7, assigns(:from) | |
296 | assert_equal Date.today, assigns(:to) |
|
305 | assert_equal Date.today, assigns(:to) | |
297 | end |
|
306 | end | |
298 |
|
307 | |||
299 | def test_issue_details_routing |
|
308 | def test_issue_details_routing | |
300 | assert_routing( |
|
309 | assert_routing( | |
301 | {:method => :get, :path => 'time_entries'}, |
|
310 | {:method => :get, :path => 'time_entries'}, | |
302 | :controller => 'timelog', :action => 'details' |
|
311 | :controller => 'timelog', :action => 'details' | |
303 | ) |
|
312 | ) | |
304 | assert_routing( |
|
313 | assert_routing( | |
305 | {:method => :get, :path => '/issues/234/time_entries'}, |
|
314 | {:method => :get, :path => '/issues/234/time_entries'}, | |
306 | :controller => 'timelog', :action => 'details', :issue_id => '234' |
|
315 | :controller => 'timelog', :action => 'details', :issue_id => '234' | |
307 | ) |
|
316 | ) | |
308 | # TODO: issue detail page shouldnt link to project_issue_time_entries_path but to normal issues one |
|
317 | # TODO: issue detail page shouldnt link to project_issue_time_entries_path but to normal issues one | |
309 | # doesnt seem to have effect on resulting page so controller can be left untouched |
|
318 | # doesnt seem to have effect on resulting page so controller can be left untouched | |
310 | assert_routing( |
|
319 | assert_routing( | |
311 | {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries'}, |
|
320 | {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries'}, | |
312 | :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123' |
|
321 | :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123' | |
313 | ) |
|
322 | ) | |
314 | end |
|
323 | end | |
315 |
|
324 | |||
316 | def test_details_at_issue_level |
|
325 | def test_details_at_issue_level | |
317 | get :details, :issue_id => 1 |
|
326 | get :details, :issue_id => 1 | |
318 | assert_response :success |
|
327 | assert_response :success | |
319 | assert_template 'details' |
|
328 | assert_template 'details' | |
320 | assert_not_nil assigns(:entries) |
|
329 | assert_not_nil assigns(:entries) | |
321 | assert_equal 2, assigns(:entries).size |
|
330 | assert_equal 2, assigns(:entries).size | |
322 | assert_not_nil assigns(:total_hours) |
|
331 | assert_not_nil assigns(:total_hours) | |
323 | assert_equal 154.25, assigns(:total_hours) |
|
332 | assert_equal 154.25, assigns(:total_hours) | |
324 | # display all time by default |
|
333 | # display all time by default | |
325 | assert_equal '2007-03-11'.to_date, assigns(:from) |
|
334 | assert_equal '2007-03-11'.to_date, assigns(:from) | |
326 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
335 | assert_equal '2007-04-22'.to_date, assigns(:to) | |
327 | end |
|
336 | end | |
328 |
|
337 | |||
329 | def test_details_formatted_routing |
|
338 | def test_details_formatted_routing | |
330 | assert_routing( |
|
339 | assert_routing( | |
331 | {:method => :get, :path => 'time_entries.atom'}, |
|
340 | {:method => :get, :path => 'time_entries.atom'}, | |
332 | :controller => 'timelog', :action => 'details', :format => 'atom' |
|
341 | :controller => 'timelog', :action => 'details', :format => 'atom' | |
333 | ) |
|
342 | ) | |
334 | assert_routing( |
|
343 | assert_routing( | |
335 | {:method => :get, :path => 'time_entries.csv'}, |
|
344 | {:method => :get, :path => 'time_entries.csv'}, | |
336 | :controller => 'timelog', :action => 'details', :format => 'csv' |
|
345 | :controller => 'timelog', :action => 'details', :format => 'csv' | |
337 | ) |
|
346 | ) | |
338 | end |
|
347 | end | |
339 |
|
348 | |||
340 | def test_details_for_project_formatted_routing |
|
349 | def test_details_for_project_formatted_routing | |
341 | assert_routing( |
|
350 | assert_routing( | |
342 | {:method => :get, :path => '/projects/567/time_entries.atom'}, |
|
351 | {:method => :get, :path => '/projects/567/time_entries.atom'}, | |
343 | :controller => 'timelog', :action => 'details', :format => 'atom', :project_id => '567' |
|
352 | :controller => 'timelog', :action => 'details', :format => 'atom', :project_id => '567' | |
344 | ) |
|
353 | ) | |
345 | assert_routing( |
|
354 | assert_routing( | |
346 | {:method => :get, :path => '/projects/567/time_entries.csv'}, |
|
355 | {:method => :get, :path => '/projects/567/time_entries.csv'}, | |
347 | :controller => 'timelog', :action => 'details', :format => 'csv', :project_id => '567' |
|
356 | :controller => 'timelog', :action => 'details', :format => 'csv', :project_id => '567' | |
348 | ) |
|
357 | ) | |
349 | end |
|
358 | end | |
350 |
|
359 | |||
351 | def test_details_for_issue_formatted_routing |
|
360 | def test_details_for_issue_formatted_routing | |
352 | assert_routing( |
|
361 | assert_routing( | |
353 | {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries.atom'}, |
|
362 | {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries.atom'}, | |
354 | :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123', :format => 'atom' |
|
363 | :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123', :format => 'atom' | |
355 | ) |
|
364 | ) | |
356 | assert_routing( |
|
365 | assert_routing( | |
357 | {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries.csv'}, |
|
366 | {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries.csv'}, | |
358 | :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123', :format => 'csv' |
|
367 | :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123', :format => 'csv' | |
359 | ) |
|
368 | ) | |
360 | end |
|
369 | end | |
361 |
|
370 | |||
362 | def test_details_atom_feed |
|
371 | def test_details_atom_feed | |
363 | get :details, :project_id => 1, :format => 'atom' |
|
372 | get :details, :project_id => 1, :format => 'atom' | |
364 | assert_response :success |
|
373 | assert_response :success | |
365 | assert_equal 'application/atom+xml', @response.content_type |
|
374 | assert_equal 'application/atom+xml', @response.content_type | |
366 | assert_not_nil assigns(:items) |
|
375 | assert_not_nil assigns(:items) | |
367 | assert assigns(:items).first.is_a?(TimeEntry) |
|
376 | assert assigns(:items).first.is_a?(TimeEntry) | |
368 | end |
|
377 | end | |
369 |
|
378 | |||
370 | def test_details_all_projects_csv_export |
|
379 | def test_details_all_projects_csv_export | |
371 | get :details, :format => 'csv' |
|
380 | get :details, :format => 'csv' | |
372 | assert_response :success |
|
381 | assert_response :success | |
373 | assert_equal 'text/csv', @response.content_type |
|
382 | assert_equal 'text/csv', @response.content_type | |
374 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") |
|
383 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") | |
375 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") |
|
384 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") | |
376 | end |
|
385 | end | |
377 |
|
386 | |||
378 | def test_details_csv_export |
|
387 | def test_details_csv_export | |
379 | get :details, :project_id => 1, :format => 'csv' |
|
388 | get :details, :project_id => 1, :format => 'csv' | |
380 | assert_response :success |
|
389 | assert_response :success | |
381 | assert_equal 'text/csv', @response.content_type |
|
390 | assert_equal 'text/csv', @response.content_type | |
382 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") |
|
391 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") | |
383 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") |
|
392 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") | |
384 | end |
|
393 | end | |
385 | end |
|
394 | end |
General Comments 0
You need to be logged in to leave comments.
Login now