@@ -1,286 +1,286 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 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 | class TimelogController < ApplicationController |
|
18 | class TimelogController < ApplicationController | |
19 | menu_item :time_entries |
|
19 | menu_item :time_entries | |
20 |
|
20 | |||
21 | before_action :find_time_entry, :only => [:show, :edit, :update] |
|
21 | before_action :find_time_entry, :only => [:show, :edit, :update] | |
22 | before_action :check_editability, :only => [:edit, :update] |
|
22 | before_action :check_editability, :only => [:edit, :update] | |
23 | before_action :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy] |
|
23 | before_action :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy] | |
24 | before_action :authorize, :only => [:show, :edit, :update, :bulk_edit, :bulk_update, :destroy] |
|
24 | before_action :authorize, :only => [:show, :edit, :update, :bulk_edit, :bulk_update, :destroy] | |
25 |
|
25 | |||
26 | before_action :find_optional_issue, :only => [:new, :create] |
|
26 | before_action :find_optional_issue, :only => [:new, :create] | |
27 | before_action :find_optional_project, :only => [:index, :report] |
|
27 | before_action :find_optional_project, :only => [:index, :report] | |
28 | before_action :authorize_global, :only => [:new, :create, :index, :report] |
|
28 | before_action :authorize_global, :only => [:new, :create, :index, :report] | |
29 |
|
29 | |||
30 | accept_rss_auth :index |
|
30 | accept_rss_auth :index | |
31 | accept_api_auth :index, :show, :create, :update, :destroy |
|
31 | accept_api_auth :index, :show, :create, :update, :destroy | |
32 |
|
32 | |||
33 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
33 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid | |
34 |
|
34 | |||
35 | helper :sort |
|
35 | helper :sort | |
36 | include SortHelper |
|
36 | include SortHelper | |
37 | helper :issues |
|
37 | helper :issues | |
38 | include TimelogHelper |
|
38 | include TimelogHelper | |
39 | helper :custom_fields |
|
39 | helper :custom_fields | |
40 | include CustomFieldsHelper |
|
40 | include CustomFieldsHelper | |
41 | helper :queries |
|
41 | helper :queries | |
42 | include QueriesHelper |
|
42 | include QueriesHelper | |
43 |
|
43 | |||
44 | def index |
|
44 | def index | |
45 | retrieve_time_entry_query |
|
45 | retrieve_time_entry_query | |
46 | sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria) |
|
46 | sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria) | |
47 | sort_update(@query.sortable_columns) |
|
47 | sort_update(@query.sortable_columns) | |
48 | scope = time_entry_scope(:order => sort_clause). |
|
48 | scope = time_entry_scope(:order => sort_clause). | |
49 | preload(:issue => [:project, :tracker, :status, :assigned_to, :priority]). |
|
49 | preload(:issue => [:project, :tracker, :status, :assigned_to, :priority]). | |
50 | preload(:project, :user) |
|
50 | preload(:project, :user) | |
51 |
|
51 | |||
52 | respond_to do |format| |
|
52 | respond_to do |format| | |
53 | format.html { |
|
53 | format.html { | |
54 | @entry_count = scope.count |
|
54 | @entry_count = scope.count | |
55 | @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] |
|
55 | @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] | |
56 | @entries = scope.offset(@entry_pages.offset).limit(@entry_pages.per_page).to_a |
|
56 | @entries = scope.offset(@entry_pages.offset).limit(@entry_pages.per_page).to_a | |
57 |
|
57 | |||
58 | render :layout => !request.xhr? |
|
58 | render :layout => !request.xhr? | |
59 | } |
|
59 | } | |
60 | format.api { |
|
60 | format.api { | |
61 | @entry_count = scope.count |
|
61 | @entry_count = scope.count | |
62 | @offset, @limit = api_offset_and_limit |
|
62 | @offset, @limit = api_offset_and_limit | |
63 | @entries = scope.offset(@offset).limit(@limit).preload(:custom_values => :custom_field).to_a |
|
63 | @entries = scope.offset(@offset).limit(@limit).preload(:custom_values => :custom_field).to_a | |
64 | } |
|
64 | } | |
65 | format.atom { |
|
65 | format.atom { | |
66 | entries = scope.limit(Setting.feeds_limit.to_i).reorder("#{TimeEntry.table_name}.created_on DESC").to_a |
|
66 | entries = scope.limit(Setting.feeds_limit.to_i).reorder("#{TimeEntry.table_name}.created_on DESC").to_a | |
67 | render_feed(entries, :title => l(:label_spent_time)) |
|
67 | render_feed(entries, :title => l(:label_spent_time)) | |
68 | } |
|
68 | } | |
69 | format.csv { |
|
69 | format.csv { | |
70 | # Export all entries |
|
70 | # Export all entries | |
71 | @entries = scope.to_a |
|
71 | @entries = scope.to_a | |
72 | send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv') |
|
72 | send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv') | |
73 | } |
|
73 | } | |
74 | end |
|
74 | end | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def report |
|
77 | def report | |
78 | retrieve_time_entry_query |
|
78 | retrieve_time_entry_query | |
79 | scope = time_entry_scope |
|
79 | scope = time_entry_scope | |
80 |
|
80 | |||
81 | @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], scope) |
|
81 | @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], scope) | |
82 |
|
82 | |||
83 | respond_to do |format| |
|
83 | respond_to do |format| | |
84 | format.html { render :layout => !request.xhr? } |
|
84 | format.html { render :layout => !request.xhr? } | |
85 | format.csv { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'timelog.csv') } |
|
85 | format.csv { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'timelog.csv') } | |
86 | end |
|
86 | end | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | def show |
|
89 | def show | |
90 | respond_to do |format| |
|
90 | respond_to do |format| | |
91 | # TODO: Implement html response |
|
91 | # TODO: Implement html response | |
92 | format.html { head 406 } |
|
92 | format.html { head 406 } | |
93 | format.api |
|
93 | format.api | |
94 | end |
|
94 | end | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def new |
|
97 | def new | |
98 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
|
98 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) | |
99 | @time_entry.safe_attributes = params[:time_entry] |
|
99 | @time_entry.safe_attributes = params[:time_entry] | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def create |
|
102 | def create | |
103 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
|
103 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) | |
104 | @time_entry.safe_attributes = params[:time_entry] |
|
104 | @time_entry.safe_attributes = params[:time_entry] | |
105 | if @time_entry.project && !User.current.allowed_to?(:log_time, @time_entry.project) |
|
105 | if @time_entry.project && !User.current.allowed_to?(:log_time, @time_entry.project) | |
106 | render_403 |
|
106 | render_403 | |
107 | return |
|
107 | return | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
|
110 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) | |
111 |
|
111 | |||
112 | if @time_entry.save |
|
112 | if @time_entry.save | |
113 | respond_to do |format| |
|
113 | respond_to do |format| | |
114 | format.html { |
|
114 | format.html { | |
115 | flash[:notice] = l(:notice_successful_create) |
|
115 | flash[:notice] = l(:notice_successful_create) | |
116 | if params[:continue] |
|
116 | if params[:continue] | |
117 | options = { |
|
117 | options = { | |
118 | :time_entry => { |
|
118 | :time_entry => { | |
119 | :project_id => params[:time_entry][:project_id], |
|
119 | :project_id => params[:time_entry][:project_id], | |
120 | :issue_id => @time_entry.issue_id, |
|
120 | :issue_id => @time_entry.issue_id, | |
121 | :activity_id => @time_entry.activity_id |
|
121 | :activity_id => @time_entry.activity_id | |
122 | }, |
|
122 | }, | |
123 | :back_url => params[:back_url] |
|
123 | :back_url => params[:back_url] | |
124 | } |
|
124 | } | |
125 | if params[:project_id] && @time_entry.project |
|
125 | if params[:project_id] && @time_entry.project | |
126 | redirect_to new_project_time_entry_path(@time_entry.project, options) |
|
126 | redirect_to new_project_time_entry_path(@time_entry.project, options) | |
127 | elsif params[:issue_id] && @time_entry.issue |
|
127 | elsif params[:issue_id] && @time_entry.issue | |
128 | redirect_to new_issue_time_entry_path(@time_entry.issue, options) |
|
128 | redirect_to new_issue_time_entry_path(@time_entry.issue, options) | |
129 | else |
|
129 | else | |
130 | redirect_to new_time_entry_path(options) |
|
130 | redirect_to new_time_entry_path(options) | |
131 | end |
|
131 | end | |
132 | else |
|
132 | else | |
133 | redirect_back_or_default project_time_entries_path(@time_entry.project) |
|
133 | redirect_back_or_default project_time_entries_path(@time_entry.project) | |
134 | end |
|
134 | end | |
135 | } |
|
135 | } | |
136 | format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) } |
|
136 | format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) } | |
137 | end |
|
137 | end | |
138 | else |
|
138 | else | |
139 | respond_to do |format| |
|
139 | respond_to do |format| | |
140 | format.html { render :action => 'new' } |
|
140 | format.html { render :action => 'new' } | |
141 | format.api { render_validation_errors(@time_entry) } |
|
141 | format.api { render_validation_errors(@time_entry) } | |
142 | end |
|
142 | end | |
143 | end |
|
143 | end | |
144 | end |
|
144 | end | |
145 |
|
145 | |||
146 | def edit |
|
146 | def edit | |
147 | @time_entry.safe_attributes = params[:time_entry] |
|
147 | @time_entry.safe_attributes = params[:time_entry] | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | def update |
|
150 | def update | |
151 | @time_entry.safe_attributes = params[:time_entry] |
|
151 | @time_entry.safe_attributes = params[:time_entry] | |
152 |
|
152 | |||
153 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
|
153 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) | |
154 |
|
154 | |||
155 | if @time_entry.save |
|
155 | if @time_entry.save | |
156 | respond_to do |format| |
|
156 | respond_to do |format| | |
157 | format.html { |
|
157 | format.html { | |
158 | flash[:notice] = l(:notice_successful_update) |
|
158 | flash[:notice] = l(:notice_successful_update) | |
159 | redirect_back_or_default project_time_entries_path(@time_entry.project) |
|
159 | redirect_back_or_default project_time_entries_path(@time_entry.project) | |
160 | } |
|
160 | } | |
161 | format.api { render_api_ok } |
|
161 | format.api { render_api_ok } | |
162 | end |
|
162 | end | |
163 | else |
|
163 | else | |
164 | respond_to do |format| |
|
164 | respond_to do |format| | |
165 | format.html { render :action => 'edit' } |
|
165 | format.html { render :action => 'edit' } | |
166 | format.api { render_validation_errors(@time_entry) } |
|
166 | format.api { render_validation_errors(@time_entry) } | |
167 | end |
|
167 | end | |
168 | end |
|
168 | end | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | def bulk_edit |
|
171 | def bulk_edit | |
172 | @available_activities = @projects.map(&:activities).reduce(:&) |
|
172 | @available_activities = @projects.map(&:activities).reduce(:&) | |
173 | @custom_fields = TimeEntry.first.available_custom_fields.select {|field| field.format.bulk_edit_supported} |
|
173 | @custom_fields = TimeEntry.first.available_custom_fields.select {|field| field.format.bulk_edit_supported} | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | def bulk_update |
|
176 | def bulk_update | |
177 | attributes = parse_params_for_bulk_update(params[:time_entry]) |
|
177 | attributes = parse_params_for_bulk_update(params[:time_entry]) | |
178 |
|
178 | |||
179 | unsaved_time_entry_ids = [] |
|
179 | unsaved_time_entry_ids = [] | |
180 | @time_entries.each do |time_entry| |
|
180 | @time_entries.each do |time_entry| | |
181 | time_entry.reload |
|
181 | time_entry.reload | |
182 | time_entry.safe_attributes = attributes |
|
182 | time_entry.safe_attributes = attributes | |
183 | call_hook(:controller_time_entries_bulk_edit_before_save, { :params => params, :time_entry => time_entry }) |
|
183 | call_hook(:controller_time_entries_bulk_edit_before_save, { :params => params, :time_entry => time_entry }) | |
184 | unless time_entry.save |
|
184 | unless time_entry.save | |
185 | logger.info "time entry could not be updated: #{time_entry.errors.full_messages}" if logger && logger.info? |
|
185 | logger.info "time entry could not be updated: #{time_entry.errors.full_messages}" if logger && logger.info? | |
186 | # Keep unsaved time_entry ids to display them in flash error |
|
186 | # Keep unsaved time_entry ids to display them in flash error | |
187 | unsaved_time_entry_ids << time_entry.id |
|
187 | unsaved_time_entry_ids << time_entry.id | |
188 | end |
|
188 | end | |
189 | end |
|
189 | end | |
190 | set_flash_from_bulk_time_entry_save(@time_entries, unsaved_time_entry_ids) |
|
190 | set_flash_from_bulk_time_entry_save(@time_entries, unsaved_time_entry_ids) | |
191 | redirect_back_or_default project_time_entries_path(@projects.first) |
|
191 | redirect_back_or_default project_time_entries_path(@projects.first) | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | def destroy |
|
194 | def destroy | |
195 | destroyed = TimeEntry.transaction do |
|
195 | destroyed = TimeEntry.transaction do | |
196 | @time_entries.each do |t| |
|
196 | @time_entries.each do |t| | |
197 | unless t.destroy && t.destroyed? |
|
197 | unless t.destroy && t.destroyed? | |
198 | raise ActiveRecord::Rollback |
|
198 | raise ActiveRecord::Rollback | |
199 | end |
|
199 | end | |
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | respond_to do |format| |
|
203 | respond_to do |format| | |
204 | format.html { |
|
204 | format.html { | |
205 | if destroyed |
|
205 | if destroyed | |
206 | flash[:notice] = l(:notice_successful_delete) |
|
206 | flash[:notice] = l(:notice_successful_delete) | |
207 | else |
|
207 | else | |
208 | flash[:error] = l(:notice_unable_delete_time_entry) |
|
208 | flash[:error] = l(:notice_unable_delete_time_entry) | |
209 | end |
|
209 | end | |
210 | redirect_back_or_default project_time_entries_path(@projects.first) |
|
210 | redirect_back_or_default project_time_entries_path(@projects.first), :referer => true | |
211 | } |
|
211 | } | |
212 | format.api { |
|
212 | format.api { | |
213 | if destroyed |
|
213 | if destroyed | |
214 | render_api_ok |
|
214 | render_api_ok | |
215 | else |
|
215 | else | |
216 | render_validation_errors(@time_entries) |
|
216 | render_validation_errors(@time_entries) | |
217 | end |
|
217 | end | |
218 | } |
|
218 | } | |
219 | end |
|
219 | end | |
220 | end |
|
220 | end | |
221 |
|
221 | |||
222 | private |
|
222 | private | |
223 | def find_time_entry |
|
223 | def find_time_entry | |
224 | @time_entry = TimeEntry.find(params[:id]) |
|
224 | @time_entry = TimeEntry.find(params[:id]) | |
225 | @project = @time_entry.project |
|
225 | @project = @time_entry.project | |
226 | rescue ActiveRecord::RecordNotFound |
|
226 | rescue ActiveRecord::RecordNotFound | |
227 | render_404 |
|
227 | render_404 | |
228 | end |
|
228 | end | |
229 |
|
229 | |||
230 | def check_editability |
|
230 | def check_editability | |
231 | unless @time_entry.editable_by?(User.current) |
|
231 | unless @time_entry.editable_by?(User.current) | |
232 | render_403 |
|
232 | render_403 | |
233 | return false |
|
233 | return false | |
234 | end |
|
234 | end | |
235 | end |
|
235 | end | |
236 |
|
236 | |||
237 | def find_time_entries |
|
237 | def find_time_entries | |
238 | @time_entries = TimeEntry.where(:id => params[:id] || params[:ids]). |
|
238 | @time_entries = TimeEntry.where(:id => params[:id] || params[:ids]). | |
239 | preload(:project => :time_entry_activities). |
|
239 | preload(:project => :time_entry_activities). | |
240 | preload(:user).to_a |
|
240 | preload(:user).to_a | |
241 |
|
241 | |||
242 | raise ActiveRecord::RecordNotFound if @time_entries.empty? |
|
242 | raise ActiveRecord::RecordNotFound if @time_entries.empty? | |
243 | raise Unauthorized unless @time_entries.all? {|t| t.editable_by?(User.current)} |
|
243 | raise Unauthorized unless @time_entries.all? {|t| t.editable_by?(User.current)} | |
244 | @projects = @time_entries.collect(&:project).compact.uniq |
|
244 | @projects = @time_entries.collect(&:project).compact.uniq | |
245 | @project = @projects.first if @projects.size == 1 |
|
245 | @project = @projects.first if @projects.size == 1 | |
246 | rescue ActiveRecord::RecordNotFound |
|
246 | rescue ActiveRecord::RecordNotFound | |
247 | render_404 |
|
247 | render_404 | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids) |
|
250 | def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids) | |
251 | if unsaved_time_entry_ids.empty? |
|
251 | if unsaved_time_entry_ids.empty? | |
252 | flash[:notice] = l(:notice_successful_update) unless time_entries.empty? |
|
252 | flash[:notice] = l(:notice_successful_update) unless time_entries.empty? | |
253 | else |
|
253 | else | |
254 | flash[:error] = l(:notice_failed_to_save_time_entries, |
|
254 | flash[:error] = l(:notice_failed_to_save_time_entries, | |
255 | :count => unsaved_time_entry_ids.size, |
|
255 | :count => unsaved_time_entry_ids.size, | |
256 | :total => time_entries.size, |
|
256 | :total => time_entries.size, | |
257 | :ids => '#' + unsaved_time_entry_ids.join(', #')) |
|
257 | :ids => '#' + unsaved_time_entry_ids.join(', #')) | |
258 | end |
|
258 | end | |
259 | end |
|
259 | end | |
260 |
|
260 | |||
261 | def find_optional_issue |
|
261 | def find_optional_issue | |
262 | if params[:issue_id].present? |
|
262 | if params[:issue_id].present? | |
263 | @issue = Issue.find(params[:issue_id]) |
|
263 | @issue = Issue.find(params[:issue_id]) | |
264 | @project = @issue.project |
|
264 | @project = @issue.project | |
265 | else |
|
265 | else | |
266 | find_optional_project |
|
266 | find_optional_project | |
267 | end |
|
267 | end | |
268 | end |
|
268 | end | |
269 |
|
269 | |||
270 | def find_optional_project |
|
270 | def find_optional_project | |
271 | if params[:project_id].present? |
|
271 | if params[:project_id].present? | |
272 | @project = Project.find(params[:project_id]) |
|
272 | @project = Project.find(params[:project_id]) | |
273 | end |
|
273 | end | |
274 | rescue ActiveRecord::RecordNotFound |
|
274 | rescue ActiveRecord::RecordNotFound | |
275 | render_404 |
|
275 | render_404 | |
276 | end |
|
276 | end | |
277 |
|
277 | |||
278 | # Returns the TimeEntry scope for index and report actions |
|
278 | # Returns the TimeEntry scope for index and report actions | |
279 | def time_entry_scope(options={}) |
|
279 | def time_entry_scope(options={}) | |
280 | @query.results_scope(options) |
|
280 | @query.results_scope(options) | |
281 | end |
|
281 | end | |
282 |
|
282 | |||
283 | def retrieve_time_entry_query |
|
283 | def retrieve_time_entry_query | |
284 | retrieve_query(TimeEntryQuery, false) |
|
284 | retrieve_query(TimeEntryQuery, false) | |
285 | end |
|
285 | end | |
286 | end |
|
286 | end |
@@ -1,1020 +1,1029 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | # Redmine - project management software |
|
2 | # Redmine - project management software | |
3 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | # Copyright (C) 2006-2016 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 |
|
20 | |||
21 | class TimelogControllerTest < Redmine::ControllerTest |
|
21 | class TimelogControllerTest < Redmine::ControllerTest | |
22 | fixtures :projects, :enabled_modules, :roles, :members, |
|
22 | fixtures :projects, :enabled_modules, :roles, :members, | |
23 | :member_roles, :issues, :time_entries, :users, |
|
23 | :member_roles, :issues, :time_entries, :users, | |
24 | :trackers, :enumerations, :issue_statuses, |
|
24 | :trackers, :enumerations, :issue_statuses, | |
25 | :custom_fields, :custom_values, |
|
25 | :custom_fields, :custom_values, | |
26 | :projects_trackers, :custom_fields_trackers, |
|
26 | :projects_trackers, :custom_fields_trackers, | |
27 | :custom_fields_projects |
|
27 | :custom_fields_projects | |
28 |
|
28 | |||
29 | include Redmine::I18n |
|
29 | include Redmine::I18n | |
30 |
|
30 | |||
31 | def test_new |
|
31 | def test_new | |
32 | @request.session[:user_id] = 3 |
|
32 | @request.session[:user_id] = 3 | |
33 | get :new |
|
33 | get :new | |
34 | assert_response :success |
|
34 | assert_response :success | |
35 |
|
35 | |||
36 | assert_select 'input[name=?][type=hidden]', 'project_id', 0 |
|
36 | assert_select 'input[name=?][type=hidden]', 'project_id', 0 | |
37 | assert_select 'input[name=?][type=hidden]', 'issue_id', 0 |
|
37 | assert_select 'input[name=?][type=hidden]', 'issue_id', 0 | |
38 | assert_select 'span[id=?]', 'time_entry_issue' |
|
38 | assert_select 'span[id=?]', 'time_entry_issue' | |
39 | assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
39 | assert_select 'select[name=?]', 'time_entry[project_id]' do | |
40 | # blank option for project |
|
40 | # blank option for project | |
41 | assert_select 'option[value=""]' |
|
41 | assert_select 'option[value=""]' | |
42 | end |
|
42 | end | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def test_new_with_project_id |
|
45 | def test_new_with_project_id | |
46 | @request.session[:user_id] = 3 |
|
46 | @request.session[:user_id] = 3 | |
47 | get :new, :params => {:project_id => 1} |
|
47 | get :new, :params => {:project_id => 1} | |
48 | assert_response :success |
|
48 | assert_response :success | |
49 |
|
49 | |||
50 | assert_select 'input[name=?][type=hidden]', 'project_id' |
|
50 | assert_select 'input[name=?][type=hidden]', 'project_id' | |
51 | assert_select 'input[name=?][type=hidden]', 'issue_id', 0 |
|
51 | assert_select 'input[name=?][type=hidden]', 'issue_id', 0 | |
52 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
52 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_new_with_issue_id |
|
55 | def test_new_with_issue_id | |
56 | @request.session[:user_id] = 3 |
|
56 | @request.session[:user_id] = 3 | |
57 | get :new, :params => {:issue_id => 2} |
|
57 | get :new, :params => {:issue_id => 2} | |
58 | assert_response :success |
|
58 | assert_response :success | |
59 |
|
59 | |||
60 | assert_select 'input[name=?][type=hidden]', 'project_id', 0 |
|
60 | assert_select 'input[name=?][type=hidden]', 'project_id', 0 | |
61 | assert_select 'input[name=?][type=hidden]', 'issue_id' |
|
61 | assert_select 'input[name=?][type=hidden]', 'issue_id' | |
62 | assert_select 'a[href=?]', '/issues/2', :text => /Feature request #2/ |
|
62 | assert_select 'a[href=?]', '/issues/2', :text => /Feature request #2/ | |
63 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
63 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_new_without_project_should_prefill_the_form |
|
66 | def test_new_without_project_should_prefill_the_form | |
67 | @request.session[:user_id] = 3 |
|
67 | @request.session[:user_id] = 3 | |
68 | get :new, :params => {:time_entry => {:project_id => '1'}} |
|
68 | get :new, :params => {:time_entry => {:project_id => '1'}} | |
69 | assert_response :success |
|
69 | assert_response :success | |
70 |
|
70 | |||
71 | assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
71 | assert_select 'select[name=?]', 'time_entry[project_id]' do | |
72 | assert_select 'option[value="1"][selected=selected]' |
|
72 | assert_select 'option[value="1"][selected=selected]' | |
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def test_new_without_project_should_deny_without_permission |
|
76 | def test_new_without_project_should_deny_without_permission | |
77 | Role.all.each {|role| role.remove_permission! :log_time} |
|
77 | Role.all.each {|role| role.remove_permission! :log_time} | |
78 | @request.session[:user_id] = 3 |
|
78 | @request.session[:user_id] = 3 | |
79 |
|
79 | |||
80 | get :new |
|
80 | get :new | |
81 | assert_response 403 |
|
81 | assert_response 403 | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def test_new_should_select_default_activity |
|
84 | def test_new_should_select_default_activity | |
85 | @request.session[:user_id] = 3 |
|
85 | @request.session[:user_id] = 3 | |
86 | get :new, :params => {:project_id => 1} |
|
86 | get :new, :params => {:project_id => 1} | |
87 | assert_response :success |
|
87 | assert_response :success | |
88 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
88 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
89 | assert_select 'option[selected=selected]', :text => 'Development' |
|
89 | assert_select 'option[selected=selected]', :text => 'Development' | |
90 | end |
|
90 | end | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_new_should_only_show_active_time_entry_activities |
|
93 | def test_new_should_only_show_active_time_entry_activities | |
94 | @request.session[:user_id] = 3 |
|
94 | @request.session[:user_id] = 3 | |
95 | get :new, :params => {:project_id => 1} |
|
95 | get :new, :params => {:project_id => 1} | |
96 | assert_response :success |
|
96 | assert_response :success | |
97 | assert_select 'option', :text => 'Inactive Activity', :count => 0 |
|
97 | assert_select 'option', :text => 'Inactive Activity', :count => 0 | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def test_post_new_as_js_should_update_activity_options |
|
100 | def test_post_new_as_js_should_update_activity_options | |
101 | @request.session[:user_id] = 3 |
|
101 | @request.session[:user_id] = 3 | |
102 | post :new, :params => {:time_entry => {:project_id => 1}, :format => 'js'} |
|
102 | post :new, :params => {:time_entry => {:project_id => 1}, :format => 'js'} | |
103 | assert_response :success |
|
103 | assert_response :success | |
104 | assert_include '#time_entry_activity_id', response.body |
|
104 | assert_include '#time_entry_activity_id', response.body | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_get_edit_existing_time |
|
107 | def test_get_edit_existing_time | |
108 | @request.session[:user_id] = 2 |
|
108 | @request.session[:user_id] = 2 | |
109 | get :edit, :params => {:id => 2, :project_id => nil} |
|
109 | get :edit, :params => {:id => 2, :project_id => nil} | |
110 | assert_response :success |
|
110 | assert_response :success | |
111 |
|
111 | |||
112 | assert_select 'form[action=?]', '/time_entries/2' |
|
112 | assert_select 'form[action=?]', '/time_entries/2' | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity |
|
115 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity | |
116 | te = TimeEntry.find(1) |
|
116 | te = TimeEntry.find(1) | |
117 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") |
|
117 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") | |
118 | te.save!(:validate => false) |
|
118 | te.save!(:validate => false) | |
119 |
|
119 | |||
120 | @request.session[:user_id] = 1 |
|
120 | @request.session[:user_id] = 1 | |
121 | get :edit, :params => {:project_id => 1, :id => 1} |
|
121 | get :edit, :params => {:project_id => 1, :id => 1} | |
122 | assert_response :success |
|
122 | assert_response :success | |
123 |
|
123 | |||
124 | # Blank option since nothing is pre-selected |
|
124 | # Blank option since nothing is pre-selected | |
125 | assert_select 'option', :text => '--- Please select ---' |
|
125 | assert_select 'option', :text => '--- Please select ---' | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def test_post_create |
|
128 | def test_post_create | |
129 | @request.session[:user_id] = 3 |
|
129 | @request.session[:user_id] = 3 | |
130 | assert_difference 'TimeEntry.count' do |
|
130 | assert_difference 'TimeEntry.count' do | |
131 | post :create, :params => { |
|
131 | post :create, :params => { | |
132 | :project_id => 1, |
|
132 | :project_id => 1, | |
133 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
133 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
134 | # Not the default activity |
|
134 | # Not the default activity | |
135 | :activity_id => '11', |
|
135 | :activity_id => '11', | |
136 | :spent_on => '2008-03-14', |
|
136 | :spent_on => '2008-03-14', | |
137 | :issue_id => '1', |
|
137 | :issue_id => '1', | |
138 | :hours => '7.3' |
|
138 | :hours => '7.3' | |
139 | } |
|
139 | } | |
140 | } |
|
140 | } | |
141 | assert_redirected_to '/projects/ecookbook/time_entries' |
|
141 | assert_redirected_to '/projects/ecookbook/time_entries' | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | t = TimeEntry.order('id DESC').first |
|
144 | t = TimeEntry.order('id DESC').first | |
145 | assert_not_nil t |
|
145 | assert_not_nil t | |
146 | assert_equal 'Some work on TimelogControllerTest', t.comments |
|
146 | assert_equal 'Some work on TimelogControllerTest', t.comments | |
147 | assert_equal 1, t.project_id |
|
147 | assert_equal 1, t.project_id | |
148 | assert_equal 1, t.issue_id |
|
148 | assert_equal 1, t.issue_id | |
149 | assert_equal 11, t.activity_id |
|
149 | assert_equal 11, t.activity_id | |
150 | assert_equal 7.3, t.hours |
|
150 | assert_equal 7.3, t.hours | |
151 | assert_equal 3, t.user_id |
|
151 | assert_equal 3, t.user_id | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | def test_post_create_with_blank_issue |
|
154 | def test_post_create_with_blank_issue | |
155 | @request.session[:user_id] = 3 |
|
155 | @request.session[:user_id] = 3 | |
156 | assert_difference 'TimeEntry.count' do |
|
156 | assert_difference 'TimeEntry.count' do | |
157 | post :create, :params => { |
|
157 | post :create, :params => { | |
158 | :project_id => 1, |
|
158 | :project_id => 1, | |
159 | :time_entry => { |
|
159 | :time_entry => { | |
160 | :comments => 'Some work on TimelogControllerTest', |
|
160 | :comments => 'Some work on TimelogControllerTest', | |
161 | # Not the default activity |
|
161 | # Not the default activity | |
162 | :activity_id => '11', |
|
162 | :activity_id => '11', | |
163 | :issue_id => '', |
|
163 | :issue_id => '', | |
164 | :spent_on => '2008-03-14', |
|
164 | :spent_on => '2008-03-14', | |
165 | :hours => '7.3' |
|
165 | :hours => '7.3' | |
166 | } |
|
166 | } | |
167 | } |
|
167 | } | |
168 | assert_redirected_to '/projects/ecookbook/time_entries' |
|
168 | assert_redirected_to '/projects/ecookbook/time_entries' | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | t = TimeEntry.order('id DESC').first |
|
171 | t = TimeEntry.order('id DESC').first | |
172 | assert_not_nil t |
|
172 | assert_not_nil t | |
173 | assert_equal 'Some work on TimelogControllerTest', t.comments |
|
173 | assert_equal 'Some work on TimelogControllerTest', t.comments | |
174 | assert_equal 1, t.project_id |
|
174 | assert_equal 1, t.project_id | |
175 | assert_nil t.issue_id |
|
175 | assert_nil t.issue_id | |
176 | assert_equal 11, t.activity_id |
|
176 | assert_equal 11, t.activity_id | |
177 | assert_equal 7.3, t.hours |
|
177 | assert_equal 7.3, t.hours | |
178 | assert_equal 3, t.user_id |
|
178 | assert_equal 3, t.user_id | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | def test_create_on_project_with_time_tracking_disabled_should_fail |
|
181 | def test_create_on_project_with_time_tracking_disabled_should_fail | |
182 | Project.find(1).disable_module! :time_tracking |
|
182 | Project.find(1).disable_module! :time_tracking | |
183 |
|
183 | |||
184 | @request.session[:user_id] = 2 |
|
184 | @request.session[:user_id] = 2 | |
185 | assert_no_difference 'TimeEntry.count' do |
|
185 | assert_no_difference 'TimeEntry.count' do | |
186 | post :create, :params => { |
|
186 | post :create, :params => { | |
187 | :time_entry => { |
|
187 | :time_entry => { | |
188 | :project_id => '1', :issue_id => '', |
|
188 | :project_id => '1', :issue_id => '', | |
189 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
189 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 | end |
|
192 | end | |
193 | end |
|
193 | end | |
194 |
|
194 | |||
195 | def test_create_on_project_without_permission_should_fail |
|
195 | def test_create_on_project_without_permission_should_fail | |
196 | Role.find(1).remove_permission! :log_time |
|
196 | Role.find(1).remove_permission! :log_time | |
197 |
|
197 | |||
198 | @request.session[:user_id] = 2 |
|
198 | @request.session[:user_id] = 2 | |
199 | assert_no_difference 'TimeEntry.count' do |
|
199 | assert_no_difference 'TimeEntry.count' do | |
200 | post :create, :params => { |
|
200 | post :create, :params => { | |
201 | :time_entry => { |
|
201 | :time_entry => { | |
202 | :project_id => '1', :issue_id => '', |
|
202 | :project_id => '1', :issue_id => '', | |
203 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
203 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 | end |
|
206 | end | |
207 | end |
|
207 | end | |
208 |
|
208 | |||
209 | def test_create_on_issue_in_project_with_time_tracking_disabled_should_fail |
|
209 | def test_create_on_issue_in_project_with_time_tracking_disabled_should_fail | |
210 | Project.find(1).disable_module! :time_tracking |
|
210 | Project.find(1).disable_module! :time_tracking | |
211 |
|
211 | |||
212 | @request.session[:user_id] = 2 |
|
212 | @request.session[:user_id] = 2 | |
213 | assert_no_difference 'TimeEntry.count' do |
|
213 | assert_no_difference 'TimeEntry.count' do | |
214 | post :create, :params => { |
|
214 | post :create, :params => { | |
215 | :time_entry => { |
|
215 | :time_entry => { | |
216 | :project_id => '', :issue_id => '1', |
|
216 | :project_id => '', :issue_id => '1', | |
217 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
217 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 | assert_select_error /Issue is invalid/ |
|
220 | assert_select_error /Issue is invalid/ | |
221 | end |
|
221 | end | |
222 | end |
|
222 | end | |
223 |
|
223 | |||
224 | def test_create_on_issue_in_project_without_permission_should_fail |
|
224 | def test_create_on_issue_in_project_without_permission_should_fail | |
225 | Role.find(1).remove_permission! :log_time |
|
225 | Role.find(1).remove_permission! :log_time | |
226 |
|
226 | |||
227 | @request.session[:user_id] = 2 |
|
227 | @request.session[:user_id] = 2 | |
228 | assert_no_difference 'TimeEntry.count' do |
|
228 | assert_no_difference 'TimeEntry.count' do | |
229 | post :create, :params => { |
|
229 | post :create, :params => { | |
230 | :time_entry => { |
|
230 | :time_entry => { | |
231 | :project_id => '', :issue_id => '1', |
|
231 | :project_id => '', :issue_id => '1', | |
232 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
232 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 | assert_select_error /Issue is invalid/ |
|
235 | assert_select_error /Issue is invalid/ | |
236 | end |
|
236 | end | |
237 | end |
|
237 | end | |
238 |
|
238 | |||
239 | def test_create_on_issue_that_is_not_visible_should_not_disclose_subject |
|
239 | def test_create_on_issue_that_is_not_visible_should_not_disclose_subject | |
240 | issue = Issue.generate!(:subject => "issue_that_is_not_visible", :is_private => true) |
|
240 | issue = Issue.generate!(:subject => "issue_that_is_not_visible", :is_private => true) | |
241 | assert !issue.visible?(User.find(3)) |
|
241 | assert !issue.visible?(User.find(3)) | |
242 |
|
242 | |||
243 | @request.session[:user_id] = 3 |
|
243 | @request.session[:user_id] = 3 | |
244 | assert_no_difference 'TimeEntry.count' do |
|
244 | assert_no_difference 'TimeEntry.count' do | |
245 | post :create, :params => { |
|
245 | post :create, :params => { | |
246 | :time_entry => { |
|
246 | :time_entry => { | |
247 | :project_id => '', :issue_id => issue.id.to_s, |
|
247 | :project_id => '', :issue_id => issue.id.to_s, | |
248 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
248 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
249 | } |
|
249 | } | |
250 | } |
|
250 | } | |
251 | end |
|
251 | end | |
252 | assert_select_error /Issue is invalid/ |
|
252 | assert_select_error /Issue is invalid/ | |
253 | assert_select "input[name=?][value=?]", "time_entry[issue_id]", issue.id.to_s |
|
253 | assert_select "input[name=?][value=?]", "time_entry[issue_id]", issue.id.to_s | |
254 | assert_select "#time_entry_issue a", 0 |
|
254 | assert_select "#time_entry_issue a", 0 | |
255 | assert !response.body.include?('issue_that_is_not_visible') |
|
255 | assert !response.body.include?('issue_that_is_not_visible') | |
256 | end |
|
256 | end | |
257 |
|
257 | |||
258 | def test_create_and_continue_at_project_level |
|
258 | def test_create_and_continue_at_project_level | |
259 | @request.session[:user_id] = 2 |
|
259 | @request.session[:user_id] = 2 | |
260 | assert_difference 'TimeEntry.count' do |
|
260 | assert_difference 'TimeEntry.count' do | |
261 | post :create, :params => { |
|
261 | post :create, :params => { | |
262 | :time_entry => { |
|
262 | :time_entry => { | |
263 | :project_id => '1', |
|
263 | :project_id => '1', | |
264 | :activity_id => '11', |
|
264 | :activity_id => '11', | |
265 | :issue_id => '', |
|
265 | :issue_id => '', | |
266 | :spent_on => '2008-03-14', |
|
266 | :spent_on => '2008-03-14', | |
267 | :hours => '7.3' |
|
267 | :hours => '7.3' | |
268 | }, |
|
268 | }, | |
269 | :continue => '1' |
|
269 | :continue => '1' | |
270 | } |
|
270 | } | |
271 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1' |
|
271 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1' | |
272 | end |
|
272 | end | |
273 | end |
|
273 | end | |
274 |
|
274 | |||
275 | def test_create_and_continue_at_issue_level |
|
275 | def test_create_and_continue_at_issue_level | |
276 | @request.session[:user_id] = 2 |
|
276 | @request.session[:user_id] = 2 | |
277 | assert_difference 'TimeEntry.count' do |
|
277 | assert_difference 'TimeEntry.count' do | |
278 | post :create, :params => { |
|
278 | post :create, :params => { | |
279 | :time_entry => { |
|
279 | :time_entry => { | |
280 | :project_id => '', |
|
280 | :project_id => '', | |
281 | :activity_id => '11', |
|
281 | :activity_id => '11', | |
282 | :issue_id => '1', |
|
282 | :issue_id => '1', | |
283 | :spent_on => '2008-03-14', |
|
283 | :spent_on => '2008-03-14', | |
284 | :hours => '7.3' |
|
284 | :hours => '7.3' | |
285 | }, |
|
285 | }, | |
286 | :continue => '1' |
|
286 | :continue => '1' | |
287 | } |
|
287 | } | |
288 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' |
|
288 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' | |
289 | end |
|
289 | end | |
290 | end |
|
290 | end | |
291 |
|
291 | |||
292 | def test_create_and_continue_with_project_id |
|
292 | def test_create_and_continue_with_project_id | |
293 | @request.session[:user_id] = 2 |
|
293 | @request.session[:user_id] = 2 | |
294 | assert_difference 'TimeEntry.count' do |
|
294 | assert_difference 'TimeEntry.count' do | |
295 | post :create, :params => { |
|
295 | post :create, :params => { | |
296 | :project_id => 1, |
|
296 | :project_id => 1, | |
297 | :time_entry => { |
|
297 | :time_entry => { | |
298 | :activity_id => '11', |
|
298 | :activity_id => '11', | |
299 | :issue_id => '', |
|
299 | :issue_id => '', | |
300 | :spent_on => '2008-03-14', |
|
300 | :spent_on => '2008-03-14', | |
301 | :hours => '7.3' |
|
301 | :hours => '7.3' | |
302 | }, |
|
302 | }, | |
303 | :continue => '1' |
|
303 | :continue => '1' | |
304 | } |
|
304 | } | |
305 | assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=' |
|
305 | assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=' | |
306 | end |
|
306 | end | |
307 | end |
|
307 | end | |
308 |
|
308 | |||
309 | def test_create_and_continue_with_issue_id |
|
309 | def test_create_and_continue_with_issue_id | |
310 | @request.session[:user_id] = 2 |
|
310 | @request.session[:user_id] = 2 | |
311 | assert_difference 'TimeEntry.count' do |
|
311 | assert_difference 'TimeEntry.count' do | |
312 | post :create, :params => { |
|
312 | post :create, :params => { | |
313 | :issue_id => 1, |
|
313 | :issue_id => 1, | |
314 | :time_entry => { |
|
314 | :time_entry => { | |
315 | :activity_id => '11', |
|
315 | :activity_id => '11', | |
316 | :issue_id => '1', |
|
316 | :issue_id => '1', | |
317 | :spent_on => '2008-03-14', |
|
317 | :spent_on => '2008-03-14', | |
318 | :hours => '7.3' |
|
318 | :hours => '7.3' | |
319 | }, |
|
319 | }, | |
320 | :continue => '1' |
|
320 | :continue => '1' | |
321 | } |
|
321 | } | |
322 | assert_redirected_to '/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' |
|
322 | assert_redirected_to '/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' | |
323 | end |
|
323 | end | |
324 | end |
|
324 | end | |
325 |
|
325 | |||
326 | def test_create_without_log_time_permission_should_be_denied |
|
326 | def test_create_without_log_time_permission_should_be_denied | |
327 | @request.session[:user_id] = 2 |
|
327 | @request.session[:user_id] = 2 | |
328 | Role.find_by_name('Manager').remove_permission! :log_time |
|
328 | Role.find_by_name('Manager').remove_permission! :log_time | |
329 | post :create, :params => { |
|
329 | post :create, :params => { | |
330 | :project_id => 1, |
|
330 | :project_id => 1, | |
331 | :time_entry => { |
|
331 | :time_entry => { | |
332 | :activity_id => '11', |
|
332 | :activity_id => '11', | |
333 | :issue_id => '', |
|
333 | :issue_id => '', | |
334 | :spent_on => '2008-03-14', |
|
334 | :spent_on => '2008-03-14', | |
335 | :hours => '7.3' |
|
335 | :hours => '7.3' | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 | assert_response 403 |
|
338 | assert_response 403 | |
339 | end |
|
339 | end | |
340 |
|
340 | |||
341 | def test_create_without_project_and_issue_should_fail |
|
341 | def test_create_without_project_and_issue_should_fail | |
342 | @request.session[:user_id] = 2 |
|
342 | @request.session[:user_id] = 2 | |
343 | post :create, :params => {:time_entry => {:issue_id => ''}} |
|
343 | post :create, :params => {:time_entry => {:issue_id => ''}} | |
344 |
|
344 | |||
345 | assert_response :success |
|
345 | assert_response :success | |
346 | assert_select_error /Project cannot be blank/ |
|
346 | assert_select_error /Project cannot be blank/ | |
347 | end |
|
347 | end | |
348 |
|
348 | |||
349 | def test_create_with_failure |
|
349 | def test_create_with_failure | |
350 | @request.session[:user_id] = 2 |
|
350 | @request.session[:user_id] = 2 | |
351 | post :create, :params => { |
|
351 | post :create, :params => { | |
352 | :project_id => 1, |
|
352 | :project_id => 1, | |
353 | :time_entry => { |
|
353 | :time_entry => { | |
354 | :activity_id => '', |
|
354 | :activity_id => '', | |
355 | :issue_id => '', |
|
355 | :issue_id => '', | |
356 | :spent_on => '2008-03-14', |
|
356 | :spent_on => '2008-03-14', | |
357 | :hours => '7.3' |
|
357 | :hours => '7.3' | |
358 | } |
|
358 | } | |
359 | } |
|
359 | } | |
360 | assert_response :success |
|
360 | assert_response :success | |
361 | end |
|
361 | end | |
362 |
|
362 | |||
363 | def test_create_without_project |
|
363 | def test_create_without_project | |
364 | @request.session[:user_id] = 2 |
|
364 | @request.session[:user_id] = 2 | |
365 | assert_difference 'TimeEntry.count' do |
|
365 | assert_difference 'TimeEntry.count' do | |
366 | post :create, :params => { |
|
366 | post :create, :params => { | |
367 | :time_entry => { |
|
367 | :time_entry => { | |
368 | :project_id => '1', |
|
368 | :project_id => '1', | |
369 | :activity_id => '11', |
|
369 | :activity_id => '11', | |
370 | :issue_id => '', |
|
370 | :issue_id => '', | |
371 | :spent_on => '2008-03-14', |
|
371 | :spent_on => '2008-03-14', | |
372 | :hours => '7.3' |
|
372 | :hours => '7.3' | |
373 | } |
|
373 | } | |
374 | } |
|
374 | } | |
375 | end |
|
375 | end | |
376 |
|
376 | |||
377 | assert_redirected_to '/projects/ecookbook/time_entries' |
|
377 | assert_redirected_to '/projects/ecookbook/time_entries' | |
378 | time_entry = TimeEntry.order('id DESC').first |
|
378 | time_entry = TimeEntry.order('id DESC').first | |
379 | assert_equal 1, time_entry.project_id |
|
379 | assert_equal 1, time_entry.project_id | |
380 | end |
|
380 | end | |
381 |
|
381 | |||
382 | def test_create_without_project_should_fail_with_issue_not_inside_project |
|
382 | def test_create_without_project_should_fail_with_issue_not_inside_project | |
383 | @request.session[:user_id] = 2 |
|
383 | @request.session[:user_id] = 2 | |
384 | assert_no_difference 'TimeEntry.count' do |
|
384 | assert_no_difference 'TimeEntry.count' do | |
385 | post :create, :params => { |
|
385 | post :create, :params => { | |
386 | :time_entry => { |
|
386 | :time_entry => { | |
387 | :project_id => '1', |
|
387 | :project_id => '1', | |
388 | :activity_id => '11', |
|
388 | :activity_id => '11', | |
389 | :issue_id => '5', |
|
389 | :issue_id => '5', | |
390 | :spent_on => '2008-03-14', |
|
390 | :spent_on => '2008-03-14', | |
391 | :hours => '7.3' |
|
391 | :hours => '7.3' | |
392 | } |
|
392 | } | |
393 | } |
|
393 | } | |
394 | end |
|
394 | end | |
395 |
|
395 | |||
396 | assert_response :success |
|
396 | assert_response :success | |
397 | assert_select_error /Issue is invalid/ |
|
397 | assert_select_error /Issue is invalid/ | |
398 | end |
|
398 | end | |
399 |
|
399 | |||
400 | def test_create_without_project_should_deny_without_permission |
|
400 | def test_create_without_project_should_deny_without_permission | |
401 | @request.session[:user_id] = 2 |
|
401 | @request.session[:user_id] = 2 | |
402 | Project.find(3).disable_module!(:time_tracking) |
|
402 | Project.find(3).disable_module!(:time_tracking) | |
403 |
|
403 | |||
404 | assert_no_difference 'TimeEntry.count' do |
|
404 | assert_no_difference 'TimeEntry.count' do | |
405 | post :create, :params => { |
|
405 | post :create, :params => { | |
406 | :time_entry => { |
|
406 | :time_entry => { | |
407 | :project_id => '3', |
|
407 | :project_id => '3', | |
408 | :activity_id => '11', |
|
408 | :activity_id => '11', | |
409 | :issue_id => '', |
|
409 | :issue_id => '', | |
410 | :spent_on => '2008-03-14', |
|
410 | :spent_on => '2008-03-14', | |
411 | :hours => '7.3' |
|
411 | :hours => '7.3' | |
412 | } |
|
412 | } | |
413 | } |
|
413 | } | |
414 | end |
|
414 | end | |
415 |
|
415 | |||
416 | assert_response 403 |
|
416 | assert_response 403 | |
417 | end |
|
417 | end | |
418 |
|
418 | |||
419 | def test_create_without_project_with_failure |
|
419 | def test_create_without_project_with_failure | |
420 | @request.session[:user_id] = 2 |
|
420 | @request.session[:user_id] = 2 | |
421 | assert_no_difference 'TimeEntry.count' do |
|
421 | assert_no_difference 'TimeEntry.count' do | |
422 | post :create, :params => { |
|
422 | post :create, :params => { | |
423 | :time_entry => { |
|
423 | :time_entry => { | |
424 | :project_id => '1', |
|
424 | :project_id => '1', | |
425 | :activity_id => '11', |
|
425 | :activity_id => '11', | |
426 | :issue_id => '', |
|
426 | :issue_id => '', | |
427 | :spent_on => '2008-03-14', |
|
427 | :spent_on => '2008-03-14', | |
428 | :hours => '' |
|
428 | :hours => '' | |
429 | } |
|
429 | } | |
430 | } |
|
430 | } | |
431 | end |
|
431 | end | |
432 |
|
432 | |||
433 | assert_response :success |
|
433 | assert_response :success | |
434 | assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
434 | assert_select 'select[name=?]', 'time_entry[project_id]' do | |
435 | assert_select 'option[value="1"][selected=selected]' |
|
435 | assert_select 'option[value="1"][selected=selected]' | |
436 | end |
|
436 | end | |
437 | end |
|
437 | end | |
438 |
|
438 | |||
439 | def test_update |
|
439 | def test_update | |
440 | entry = TimeEntry.find(1) |
|
440 | entry = TimeEntry.find(1) | |
441 | assert_equal 1, entry.issue_id |
|
441 | assert_equal 1, entry.issue_id | |
442 | assert_equal 2, entry.user_id |
|
442 | assert_equal 2, entry.user_id | |
443 |
|
443 | |||
444 | @request.session[:user_id] = 1 |
|
444 | @request.session[:user_id] = 1 | |
445 | put :update, :params => { |
|
445 | put :update, :params => { | |
446 | :id => 1, |
|
446 | :id => 1, | |
447 | :time_entry => { |
|
447 | :time_entry => { | |
448 | :issue_id => '2', |
|
448 | :issue_id => '2', | |
449 | :hours => '8' |
|
449 | :hours => '8' | |
450 | } |
|
450 | } | |
451 | } |
|
451 | } | |
452 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
452 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
453 | entry.reload |
|
453 | entry.reload | |
454 |
|
454 | |||
455 | assert_equal 8, entry.hours |
|
455 | assert_equal 8, entry.hours | |
456 | assert_equal 2, entry.issue_id |
|
456 | assert_equal 2, entry.issue_id | |
457 | assert_equal 2, entry.user_id |
|
457 | assert_equal 2, entry.user_id | |
458 | end |
|
458 | end | |
459 |
|
459 | |||
460 | def test_update_should_allow_to_change_issue_to_another_project |
|
460 | def test_update_should_allow_to_change_issue_to_another_project | |
461 | entry = TimeEntry.generate!(:issue_id => 1) |
|
461 | entry = TimeEntry.generate!(:issue_id => 1) | |
462 |
|
462 | |||
463 | @request.session[:user_id] = 1 |
|
463 | @request.session[:user_id] = 1 | |
464 | put :update, :params => { |
|
464 | put :update, :params => { | |
465 | :id => entry.id, |
|
465 | :id => entry.id, | |
466 | :time_entry => { |
|
466 | :time_entry => { | |
467 | :issue_id => '5' |
|
467 | :issue_id => '5' | |
468 | } |
|
468 | } | |
469 | } |
|
469 | } | |
470 | assert_response 302 |
|
470 | assert_response 302 | |
471 | entry.reload |
|
471 | entry.reload | |
472 |
|
472 | |||
473 | assert_equal 5, entry.issue_id |
|
473 | assert_equal 5, entry.issue_id | |
474 | assert_equal 3, entry.project_id |
|
474 | assert_equal 3, entry.project_id | |
475 | end |
|
475 | end | |
476 |
|
476 | |||
477 | def test_update_should_not_allow_to_change_issue_to_an_invalid_project |
|
477 | def test_update_should_not_allow_to_change_issue_to_an_invalid_project | |
478 | entry = TimeEntry.generate!(:issue_id => 1) |
|
478 | entry = TimeEntry.generate!(:issue_id => 1) | |
479 | Project.find(3).disable_module!(:time_tracking) |
|
479 | Project.find(3).disable_module!(:time_tracking) | |
480 |
|
480 | |||
481 | @request.session[:user_id] = 1 |
|
481 | @request.session[:user_id] = 1 | |
482 | put :update, :params => { |
|
482 | put :update, :params => { | |
483 | :id => entry.id, |
|
483 | :id => entry.id, | |
484 | :time_entry => { |
|
484 | :time_entry => { | |
485 | :issue_id => '5' |
|
485 | :issue_id => '5' | |
486 | } |
|
486 | } | |
487 | } |
|
487 | } | |
488 | assert_response :success |
|
488 | assert_response :success | |
489 | assert_select_error /Issue is invalid/ |
|
489 | assert_select_error /Issue is invalid/ | |
490 | end |
|
490 | end | |
491 |
|
491 | |||
492 | def test_get_bulk_edit |
|
492 | def test_get_bulk_edit | |
493 | @request.session[:user_id] = 2 |
|
493 | @request.session[:user_id] = 2 | |
494 |
|
494 | |||
495 | get :bulk_edit, :params => {:ids => [1, 2]} |
|
495 | get :bulk_edit, :params => {:ids => [1, 2]} | |
496 | assert_response :success |
|
496 | assert_response :success | |
497 |
|
497 | |||
498 | assert_select 'ul#bulk-selection' do |
|
498 | assert_select 'ul#bulk-selection' do | |
499 | assert_select 'li', 2 |
|
499 | assert_select 'li', 2 | |
500 | assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours' |
|
500 | assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours' | |
501 | end |
|
501 | end | |
502 |
|
502 | |||
503 | assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do |
|
503 | assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do | |
504 | # System wide custom field |
|
504 | # System wide custom field | |
505 | assert_select 'select[name=?]', 'time_entry[custom_field_values][10]' |
|
505 | assert_select 'select[name=?]', 'time_entry[custom_field_values][10]' | |
506 |
|
506 | |||
507 | # Activities |
|
507 | # Activities | |
508 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
508 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
509 | assert_select 'option[value=""]', :text => '(No change)' |
|
509 | assert_select 'option[value=""]', :text => '(No change)' | |
510 | assert_select 'option[value="9"]', :text => 'Design' |
|
510 | assert_select 'option[value="9"]', :text => 'Design' | |
511 | end |
|
511 | end | |
512 | end |
|
512 | end | |
513 | end |
|
513 | end | |
514 |
|
514 | |||
515 | def test_get_bulk_edit_on_different_projects |
|
515 | def test_get_bulk_edit_on_different_projects | |
516 | @request.session[:user_id] = 2 |
|
516 | @request.session[:user_id] = 2 | |
517 |
|
517 | |||
518 | get :bulk_edit, :params => {:ids => [1, 2, 6]} |
|
518 | get :bulk_edit, :params => {:ids => [1, 2, 6]} | |
519 | assert_response :success |
|
519 | assert_response :success | |
520 | end |
|
520 | end | |
521 |
|
521 | |||
522 | def test_bulk_edit_with_edit_own_time_entries_permission |
|
522 | def test_bulk_edit_with_edit_own_time_entries_permission | |
523 | @request.session[:user_id] = 2 |
|
523 | @request.session[:user_id] = 2 | |
524 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
524 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
525 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries |
|
525 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries | |
526 | ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id} |
|
526 | ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id} | |
527 |
|
527 | |||
528 | get :bulk_edit, :params => {:ids => ids} |
|
528 | get :bulk_edit, :params => {:ids => ids} | |
529 | assert_response :success |
|
529 | assert_response :success | |
530 | end |
|
530 | end | |
531 |
|
531 | |||
532 | def test_bulk_update |
|
532 | def test_bulk_update | |
533 | @request.session[:user_id] = 2 |
|
533 | @request.session[:user_id] = 2 | |
534 | # update time entry activity |
|
534 | # update time entry activity | |
535 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :activity_id => 9}} |
|
535 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :activity_id => 9}} | |
536 |
|
536 | |||
537 | assert_response 302 |
|
537 | assert_response 302 | |
538 | # check that the issues were updated |
|
538 | # check that the issues were updated | |
539 | assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id} |
|
539 | assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id} | |
540 | end |
|
540 | end | |
541 |
|
541 | |||
542 | def test_bulk_update_with_failure |
|
542 | def test_bulk_update_with_failure | |
543 | @request.session[:user_id] = 2 |
|
543 | @request.session[:user_id] = 2 | |
544 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :hours => 'A'}} |
|
544 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :hours => 'A'}} | |
545 |
|
545 | |||
546 | assert_response 302 |
|
546 | assert_response 302 | |
547 | assert_match /Failed to save 2 time entrie/, flash[:error] |
|
547 | assert_match /Failed to save 2 time entrie/, flash[:error] | |
548 | end |
|
548 | end | |
549 |
|
549 | |||
550 | def test_bulk_update_on_different_projects |
|
550 | def test_bulk_update_on_different_projects | |
551 | @request.session[:user_id] = 2 |
|
551 | @request.session[:user_id] = 2 | |
552 | # makes user a manager on the other project |
|
552 | # makes user a manager on the other project | |
553 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) |
|
553 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) | |
554 |
|
554 | |||
555 | # update time entry activity |
|
555 | # update time entry activity | |
556 | post :bulk_update, :params => {:ids => [1, 2, 4], :time_entry => { :activity_id => 9 }} |
|
556 | post :bulk_update, :params => {:ids => [1, 2, 4], :time_entry => { :activity_id => 9 }} | |
557 |
|
557 | |||
558 | assert_response 302 |
|
558 | assert_response 302 | |
559 | # check that the issues were updated |
|
559 | # check that the issues were updated | |
560 | assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id} |
|
560 | assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id} | |
561 | end |
|
561 | end | |
562 |
|
562 | |||
563 | def test_bulk_update_on_different_projects_without_rights |
|
563 | def test_bulk_update_on_different_projects_without_rights | |
564 | @request.session[:user_id] = 3 |
|
564 | @request.session[:user_id] = 3 | |
565 | user = User.find(3) |
|
565 | user = User.find(3) | |
566 | action = { :controller => "timelog", :action => "bulk_update" } |
|
566 | action = { :controller => "timelog", :action => "bulk_update" } | |
567 | assert user.allowed_to?(action, TimeEntry.find(1).project) |
|
567 | assert user.allowed_to?(action, TimeEntry.find(1).project) | |
568 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) |
|
568 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) | |
569 |
|
569 | |||
570 | post :bulk_update, :params => {:ids => [1, 5], :time_entry => { :activity_id => 9 }} |
|
570 | post :bulk_update, :params => {:ids => [1, 5], :time_entry => { :activity_id => 9 }} | |
571 | assert_response 403 |
|
571 | assert_response 403 | |
572 | end |
|
572 | end | |
573 |
|
573 | |||
574 | def test_bulk_update_with_edit_own_time_entries_permission |
|
574 | def test_bulk_update_with_edit_own_time_entries_permission | |
575 | @request.session[:user_id] = 2 |
|
575 | @request.session[:user_id] = 2 | |
576 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
576 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
577 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries |
|
577 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries | |
578 | ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id} |
|
578 | ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id} | |
579 |
|
579 | |||
580 | post :bulk_update, :params => {:ids => ids, :time_entry => { :activity_id => 9 }} |
|
580 | post :bulk_update, :params => {:ids => ids, :time_entry => { :activity_id => 9 }} | |
581 | assert_response 302 |
|
581 | assert_response 302 | |
582 | end |
|
582 | end | |
583 |
|
583 | |||
584 | def test_bulk_update_with_edit_own_time_entries_permissions_should_be_denied_for_time_entries_of_other_user |
|
584 | def test_bulk_update_with_edit_own_time_entries_permissions_should_be_denied_for_time_entries_of_other_user | |
585 | @request.session[:user_id] = 2 |
|
585 | @request.session[:user_id] = 2 | |
586 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
586 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
587 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries |
|
587 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries | |
588 |
|
588 | |||
589 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :activity_id => 9 }} |
|
589 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :activity_id => 9 }} | |
590 | assert_response 403 |
|
590 | assert_response 403 | |
591 | end |
|
591 | end | |
592 |
|
592 | |||
593 | def test_bulk_update_custom_field |
|
593 | def test_bulk_update_custom_field | |
594 | @request.session[:user_id] = 2 |
|
594 | @request.session[:user_id] = 2 | |
595 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }} |
|
595 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }} | |
596 |
|
596 | |||
597 | assert_response 302 |
|
597 | assert_response 302 | |
598 | assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value} |
|
598 | assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value} | |
599 | end |
|
599 | end | |
600 |
|
600 | |||
601 | def test_bulk_update_clear_custom_field |
|
601 | def test_bulk_update_clear_custom_field | |
602 | field = TimeEntryCustomField.generate!(:field_format => 'string') |
|
602 | field = TimeEntryCustomField.generate!(:field_format => 'string') | |
603 | @request.session[:user_id] = 2 |
|
603 | @request.session[:user_id] = 2 | |
604 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :custom_field_values => {field.id.to_s => '__none__'} }} |
|
604 | post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :custom_field_values => {field.id.to_s => '__none__'} }} | |
605 |
|
605 | |||
606 | assert_response 302 |
|
606 | assert_response 302 | |
607 | assert_equal ["", ""], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(field).value} |
|
607 | assert_equal ["", ""], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(field).value} | |
608 | end |
|
608 | end | |
609 |
|
609 | |||
610 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
610 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter | |
611 | @request.session[:user_id] = 2 |
|
611 | @request.session[:user_id] = 2 | |
612 | post :bulk_update, :params => {:ids => [1,2], :back_url => '/time_entries'} |
|
612 | post :bulk_update, :params => {:ids => [1,2], :back_url => '/time_entries'} | |
613 |
|
613 | |||
614 | assert_response :redirect |
|
614 | assert_response :redirect | |
615 | assert_redirected_to '/time_entries' |
|
615 | assert_redirected_to '/time_entries' | |
616 | end |
|
616 | end | |
617 |
|
617 | |||
618 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
618 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
619 | @request.session[:user_id] = 2 |
|
619 | @request.session[:user_id] = 2 | |
620 | post :bulk_update, :params => {:ids => [1,2], :back_url => 'http://google.com'} |
|
620 | post :bulk_update, :params => {:ids => [1,2], :back_url => 'http://google.com'} | |
621 |
|
621 | |||
622 | assert_response :redirect |
|
622 | assert_response :redirect | |
623 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier |
|
623 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier | |
624 | end |
|
624 | end | |
625 |
|
625 | |||
626 | def test_post_bulk_update_without_edit_permission_should_be_denied |
|
626 | def test_post_bulk_update_without_edit_permission_should_be_denied | |
627 | @request.session[:user_id] = 2 |
|
627 | @request.session[:user_id] = 2 | |
628 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
628 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
629 |
|
629 | |||
630 | post :bulk_update, :params => {:ids => [1,2]} |
|
630 | post :bulk_update, :params => {:ids => [1,2]} | |
631 | assert_response 403 |
|
631 | assert_response 403 | |
632 | end |
|
632 | end | |
633 |
|
633 | |||
634 | def test_destroy |
|
634 | def test_destroy | |
635 | @request.session[:user_id] = 2 |
|
635 | @request.session[:user_id] = 2 | |
636 |
|
636 | |||
637 | delete :destroy, :params => {:id => 1} |
|
637 | delete :destroy, :params => {:id => 1} | |
638 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
638 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
639 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] |
|
639 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] | |
640 | assert_nil TimeEntry.find_by_id(1) |
|
640 | assert_nil TimeEntry.find_by_id(1) | |
641 | end |
|
641 | end | |
642 |
|
642 | |||
643 | def test_destroy_should_fail |
|
643 | def test_destroy_should_fail | |
644 | # simulate that this fails (e.g. due to a plugin), see #5700 |
|
644 | # simulate that this fails (e.g. due to a plugin), see #5700 | |
645 | TimeEntry.any_instance.expects(:destroy).returns(false) |
|
645 | TimeEntry.any_instance.expects(:destroy).returns(false) | |
646 | @request.session[:user_id] = 2 |
|
646 | @request.session[:user_id] = 2 | |
647 |
|
647 | |||
648 | delete :destroy, :params => {:id => 1} |
|
648 | delete :destroy, :params => {:id => 1} | |
649 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
649 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
650 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] |
|
650 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] | |
651 | assert_not_nil TimeEntry.find_by_id(1) |
|
651 | assert_not_nil TimeEntry.find_by_id(1) | |
652 | end |
|
652 | end | |
653 |
|
653 | |||
|
654 | def test_destroy_should_redirect_to_referer | |||
|
655 | referer = 'http://test.host/time_entries?utf8=β&set_filter=1&&f%5B%5D=user_id&op%5Buser_id%5D=%3D&v%5Buser_id%5D%5B%5D=me' | |||
|
656 | @request.env["HTTP_REFERER"] = referer | |||
|
657 | @request.session[:user_id] = 2 | |||
|
658 | ||||
|
659 | delete :destroy, :params => {:id => 1} | |||
|
660 | assert_redirected_to referer | |||
|
661 | end | |||
|
662 | ||||
654 | def test_index_all_projects |
|
663 | def test_index_all_projects | |
655 | get :index |
|
664 | get :index | |
656 | assert_response :success |
|
665 | assert_response :success | |
657 |
|
666 | |||
658 | assert_select '.total-for-hours', :text => 'Hours: 162.90' |
|
667 | assert_select '.total-for-hours', :text => 'Hours: 162.90' | |
659 | assert_select 'form#query_form[action=?]', '/time_entries' |
|
668 | assert_select 'form#query_form[action=?]', '/time_entries' | |
660 | end |
|
669 | end | |
661 |
|
670 | |||
662 | def test_index_all_projects_should_show_log_time_link |
|
671 | def test_index_all_projects_should_show_log_time_link | |
663 | @request.session[:user_id] = 2 |
|
672 | @request.session[:user_id] = 2 | |
664 | get :index |
|
673 | get :index | |
665 | assert_response :success |
|
674 | assert_response :success | |
666 |
|
675 | |||
667 | assert_select 'a[href=?]', '/time_entries/new', :text => /Log time/ |
|
676 | assert_select 'a[href=?]', '/time_entries/new', :text => /Log time/ | |
668 | end |
|
677 | end | |
669 |
|
678 | |||
670 | def test_index_my_spent_time |
|
679 | def test_index_my_spent_time | |
671 | @request.session[:user_id] = 2 |
|
680 | @request.session[:user_id] = 2 | |
672 | get :index, :params => {:user_id => 'me', :c => ['user']} |
|
681 | get :index, :params => {:user_id => 'me', :c => ['user']} | |
673 | assert_response :success |
|
682 | assert_response :success | |
674 |
|
683 | |||
675 | users = css_select('table.time-entries tbody td.user').map(&:text).uniq |
|
684 | users = css_select('table.time-entries tbody td.user').map(&:text).uniq | |
676 | assert_equal ["John Smith"], users |
|
685 | assert_equal ["John Smith"], users | |
677 | end |
|
686 | end | |
678 |
|
687 | |||
679 | def test_index_at_project_level |
|
688 | def test_index_at_project_level | |
680 | get :index, :params => {:project_id => 'ecookbook', :c => ['project']} |
|
689 | get :index, :params => {:project_id => 'ecookbook', :c => ['project']} | |
681 | assert_response :success |
|
690 | assert_response :success | |
682 |
|
691 | |||
683 | assert_select 'tr.time-entry', 4 |
|
692 | assert_select 'tr.time-entry', 4 | |
684 |
|
693 | |||
685 | # project and subproject |
|
694 | # project and subproject | |
686 | projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort |
|
695 | projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort | |
687 | assert_equal ["eCookbook", "eCookbook Subproject 1"], projects |
|
696 | assert_equal ["eCookbook", "eCookbook Subproject 1"], projects | |
688 |
|
697 | |||
689 | assert_select '.total-for-hours', :text => 'Hours: 162.90' |
|
698 | assert_select '.total-for-hours', :text => 'Hours: 162.90' | |
690 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' |
|
699 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' | |
691 | end |
|
700 | end | |
692 |
|
701 | |||
693 | def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries |
|
702 | def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries | |
694 | entry = TimeEntry.generate!(:project => Project.find(3)) |
|
703 | entry = TimeEntry.generate!(:project => Project.find(3)) | |
695 |
|
704 | |||
696 | with_settings :display_subprojects_issues => '0' do |
|
705 | with_settings :display_subprojects_issues => '0' do | |
697 | get :index, :params => {:project_id => 'ecookbook', :c => ['project']} |
|
706 | get :index, :params => {:project_id => 'ecookbook', :c => ['project']} | |
698 | assert_response :success |
|
707 | assert_response :success | |
699 |
|
708 | |||
700 | projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort |
|
709 | projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort | |
701 | assert_equal ["eCookbook"], projects |
|
710 | assert_equal ["eCookbook"], projects | |
702 | end |
|
711 | end | |
703 | end |
|
712 | end | |
704 |
|
713 | |||
705 | def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries |
|
714 | def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries | |
706 | entry = TimeEntry.generate!(:project => Project.find(3)) |
|
715 | entry = TimeEntry.generate!(:project => Project.find(3)) | |
707 |
|
716 | |||
708 | with_settings :display_subprojects_issues => '0' do |
|
717 | with_settings :display_subprojects_issues => '0' do | |
709 | get :index, :params => {:project_id => 'ecookbook', :c => ['project'], :subproject_id => 3} |
|
718 | get :index, :params => {:project_id => 'ecookbook', :c => ['project'], :subproject_id => 3} | |
710 | assert_response :success |
|
719 | assert_response :success | |
711 |
|
720 | |||
712 | projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort |
|
721 | projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort | |
713 | assert_equal ["eCookbook", "eCookbook Subproject 1"], projects |
|
722 | assert_equal ["eCookbook", "eCookbook Subproject 1"], projects | |
714 | end |
|
723 | end | |
715 | end |
|
724 | end | |
716 |
|
725 | |||
717 | def test_index_at_project_level_with_issue_id_short_filter |
|
726 | def test_index_at_project_level_with_issue_id_short_filter | |
718 | issue = Issue.generate!(:project_id => 1) |
|
727 | issue = Issue.generate!(:project_id => 1) | |
719 | TimeEntry.generate!(:issue => issue, :hours => 4) |
|
728 | TimeEntry.generate!(:issue => issue, :hours => 4) | |
720 | TimeEntry.generate!(:issue => issue, :hours => 3) |
|
729 | TimeEntry.generate!(:issue => issue, :hours => 3) | |
721 | @request.session[:user_id] = 2 |
|
730 | @request.session[:user_id] = 2 | |
722 |
|
731 | |||
723 | get :index, :params => {:project_id => 'ecookbook', :issue_id => issue.id.to_s, :set_filter => 1} |
|
732 | get :index, :params => {:project_id => 'ecookbook', :issue_id => issue.id.to_s, :set_filter => 1} | |
724 | assert_select '.total-for-hours', :text => 'Hours: 7.00' |
|
733 | assert_select '.total-for-hours', :text => 'Hours: 7.00' | |
725 | end |
|
734 | end | |
726 |
|
735 | |||
727 | def test_index_at_project_level_with_issue_fixed_version_id_short_filter |
|
736 | def test_index_at_project_level_with_issue_fixed_version_id_short_filter | |
728 | version = Version.generate!(:project_id => 1) |
|
737 | version = Version.generate!(:project_id => 1) | |
729 | issue = Issue.generate!(:project_id => 1, :fixed_version => version) |
|
738 | issue = Issue.generate!(:project_id => 1, :fixed_version => version) | |
730 | TimeEntry.generate!(:issue => issue, :hours => 2) |
|
739 | TimeEntry.generate!(:issue => issue, :hours => 2) | |
731 | TimeEntry.generate!(:issue => issue, :hours => 3) |
|
740 | TimeEntry.generate!(:issue => issue, :hours => 3) | |
732 | @request.session[:user_id] = 2 |
|
741 | @request.session[:user_id] = 2 | |
733 |
|
742 | |||
734 | get :index, :params => {:project_id => 'ecookbook', :"issue.fixed_version_id" => version.id.to_s, :set_filter => 1} |
|
743 | get :index, :params => {:project_id => 'ecookbook', :"issue.fixed_version_id" => version.id.to_s, :set_filter => 1} | |
735 | assert_select '.total-for-hours', :text => 'Hours: 5.00' |
|
744 | assert_select '.total-for-hours', :text => 'Hours: 5.00' | |
736 | end |
|
745 | end | |
737 |
|
746 | |||
738 | def test_index_at_project_level_with_date_range |
|
747 | def test_index_at_project_level_with_date_range | |
739 | get :index, :params => { |
|
748 | get :index, :params => { | |
740 | :project_id => 'ecookbook', |
|
749 | :project_id => 'ecookbook', | |
741 | :f => ['spent_on'], |
|
750 | :f => ['spent_on'], | |
742 | :op => {'spent_on' => '><'}, |
|
751 | :op => {'spent_on' => '><'}, | |
743 | :v => {'spent_on' => ['2007-03-20', '2007-04-30']} |
|
752 | :v => {'spent_on' => ['2007-03-20', '2007-04-30']} | |
744 | } |
|
753 | } | |
745 | assert_response :success |
|
754 | assert_response :success | |
746 |
|
755 | |||
747 | assert_select 'tr.time-entry', 3 |
|
756 | assert_select 'tr.time-entry', 3 | |
748 | assert_select '.total-for-hours', :text => 'Hours: 12.90' |
|
757 | assert_select '.total-for-hours', :text => 'Hours: 12.90' | |
749 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' |
|
758 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' | |
750 | end |
|
759 | end | |
751 |
|
760 | |||
752 | def test_index_at_project_level_with_date_range_using_from_and_to_params |
|
761 | def test_index_at_project_level_with_date_range_using_from_and_to_params | |
753 | get :index, :params => { |
|
762 | get :index, :params => { | |
754 | :project_id => 'ecookbook', |
|
763 | :project_id => 'ecookbook', | |
755 | :from => '2007-03-20', |
|
764 | :from => '2007-03-20', | |
756 | :to => '2007-04-30' |
|
765 | :to => '2007-04-30' | |
757 | } |
|
766 | } | |
758 | assert_response :success |
|
767 | assert_response :success | |
759 |
|
768 | |||
760 | assert_select 'tr.time-entry', 3 |
|
769 | assert_select 'tr.time-entry', 3 | |
761 | assert_select '.total-for-hours', :text => 'Hours: 12.90' |
|
770 | assert_select '.total-for-hours', :text => 'Hours: 12.90' | |
762 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' |
|
771 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' | |
763 | end |
|
772 | end | |
764 |
|
773 | |||
765 | def test_index_at_project_level_with_period |
|
774 | def test_index_at_project_level_with_period | |
766 | get :index, :params => { |
|
775 | get :index, :params => { | |
767 | :project_id => 'ecookbook', |
|
776 | :project_id => 'ecookbook', | |
768 | :f => ['spent_on'], |
|
777 | :f => ['spent_on'], | |
769 | :op => {'spent_on' => '>t-'}, |
|
778 | :op => {'spent_on' => '>t-'}, | |
770 | :v => {'spent_on' => ['7']} |
|
779 | :v => {'spent_on' => ['7']} | |
771 | } |
|
780 | } | |
772 | assert_response :success |
|
781 | assert_response :success | |
773 |
|
782 | |||
774 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' |
|
783 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' | |
775 | end |
|
784 | end | |
776 |
|
785 | |||
777 | def test_index_should_sort_by_spent_on_and_created_on |
|
786 | def test_index_should_sort_by_spent_on_and_created_on | |
778 | t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10) |
|
787 | t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10) | |
779 | t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10) |
|
788 | t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10) | |
780 | t3 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-15', :created_on => '2012-06-16 20:10:00', :activity_id => 10) |
|
789 | t3 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-15', :created_on => '2012-06-16 20:10:00', :activity_id => 10) | |
781 |
|
790 | |||
782 | get :index, :params => { |
|
791 | get :index, :params => { | |
783 | :project_id => 1, |
|
792 | :project_id => 1, | |
784 | :f => ['spent_on'], |
|
793 | :f => ['spent_on'], | |
785 | :op => {'spent_on' => '><'}, |
|
794 | :op => {'spent_on' => '><'}, | |
786 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']} |
|
795 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']} | |
787 | } |
|
796 | } | |
788 | assert_response :success |
|
797 | assert_response :success | |
789 | assert_equal [t2, t1, t3].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} |
|
798 | assert_equal [t2, t1, t3].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} | |
790 |
|
799 | |||
791 | get :index, :params => { |
|
800 | get :index, :params => { | |
792 | :project_id => 1, |
|
801 | :project_id => 1, | |
793 | :f => ['spent_on'], |
|
802 | :f => ['spent_on'], | |
794 | :op => {'spent_on' => '><'}, |
|
803 | :op => {'spent_on' => '><'}, | |
795 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']}, |
|
804 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']}, | |
796 | :sort => 'spent_on' |
|
805 | :sort => 'spent_on' | |
797 | } |
|
806 | } | |
798 | assert_response :success |
|
807 | assert_response :success | |
799 | assert_equal [t3, t1, t2].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} |
|
808 | assert_equal [t3, t1, t2].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} | |
800 | end |
|
809 | end | |
801 |
|
810 | |||
802 | def test_index_with_issue_status_filter |
|
811 | def test_index_with_issue_status_filter | |
803 | Issue.where(:status_id => 4).update_all(:status_id => 2) |
|
812 | Issue.where(:status_id => 4).update_all(:status_id => 2) | |
804 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4) |
|
813 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4) | |
805 | entry = TimeEntry.generate!(:issue => issue, :hours => 4.5) |
|
814 | entry = TimeEntry.generate!(:issue => issue, :hours => 4.5) | |
806 |
|
815 | |||
807 | get :index, :params => { |
|
816 | get :index, :params => { | |
808 | :f => ['issue.status_id'], |
|
817 | :f => ['issue.status_id'], | |
809 | :op => {'issue.status_id' => '='}, |
|
818 | :op => {'issue.status_id' => '='}, | |
810 | :v => {'issue.status_id' => ['4']} |
|
819 | :v => {'issue.status_id' => ['4']} | |
811 | } |
|
820 | } | |
812 | assert_response :success |
|
821 | assert_response :success | |
813 | assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} |
|
822 | assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} | |
814 | end |
|
823 | end | |
815 |
|
824 | |||
816 | def test_index_with_issue_status_column |
|
825 | def test_index_with_issue_status_column | |
817 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4) |
|
826 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4) | |
818 | entry = TimeEntry.generate!(:issue => issue) |
|
827 | entry = TimeEntry.generate!(:issue => issue) | |
819 |
|
828 | |||
820 | get :index, :params => { |
|
829 | get :index, :params => { | |
821 | :c => %w(project spent_on issue comments hours issue.status) |
|
830 | :c => %w(project spent_on issue comments hours issue.status) | |
822 | } |
|
831 | } | |
823 | assert_response :success |
|
832 | assert_response :success | |
824 | assert_select 'td.issue-status', :text => issue.status.name |
|
833 | assert_select 'td.issue-status', :text => issue.status.name | |
825 | end |
|
834 | end | |
826 |
|
835 | |||
827 | def test_index_with_issue_status_sort |
|
836 | def test_index_with_issue_status_sort | |
828 | TimeEntry.delete_all |
|
837 | TimeEntry.delete_all | |
829 | TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 1)) |
|
838 | TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 1)) | |
830 | TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 5)) |
|
839 | TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 5)) | |
831 | TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 3)) |
|
840 | TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 3)) | |
832 | TimeEntry.generate!(:project_id => 1) |
|
841 | TimeEntry.generate!(:project_id => 1) | |
833 |
|
842 | |||
834 | get :index, :params => { |
|
843 | get :index, :params => { | |
835 | :c => ["hours", 'issue.status'], |
|
844 | :c => ["hours", 'issue.status'], | |
836 | :sort => 'issue.status' |
|
845 | :sort => 'issue.status' | |
837 | } |
|
846 | } | |
838 | assert_response :success |
|
847 | assert_response :success | |
839 |
|
848 | |||
840 | # Make sure that values are properly sorted |
|
849 | # Make sure that values are properly sorted | |
841 | values = css_select("td.issue-status").map(&:text).reject(&:blank?) |
|
850 | values = css_select("td.issue-status").map(&:text).reject(&:blank?) | |
842 | assert_equal IssueStatus.where(:id => [1, 5, 3]).sorted.pluck(:name), values |
|
851 | assert_equal IssueStatus.where(:id => [1, 5, 3]).sorted.pluck(:name), values | |
843 | end |
|
852 | end | |
844 |
|
853 | |||
845 | def test_index_with_issue_tracker_filter |
|
854 | def test_index_with_issue_tracker_filter | |
846 | Issue.where(:tracker_id => 2).update_all(:tracker_id => 1) |
|
855 | Issue.where(:tracker_id => 2).update_all(:tracker_id => 1) | |
847 | issue = Issue.generate!(:project_id => 1, :tracker_id => 2) |
|
856 | issue = Issue.generate!(:project_id => 1, :tracker_id => 2) | |
848 | entry = TimeEntry.generate!(:issue => issue, :hours => 4.5) |
|
857 | entry = TimeEntry.generate!(:issue => issue, :hours => 4.5) | |
849 |
|
858 | |||
850 | get :index, :params => { |
|
859 | get :index, :params => { | |
851 | :f => ['issue.tracker_id'], |
|
860 | :f => ['issue.tracker_id'], | |
852 | :op => {'issue.tracker_id' => '='}, |
|
861 | :op => {'issue.tracker_id' => '='}, | |
853 | :v => {'issue.tracker_id' => ['2']} |
|
862 | :v => {'issue.tracker_id' => ['2']} | |
854 | } |
|
863 | } | |
855 | assert_response :success |
|
864 | assert_response :success | |
856 | assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} |
|
865 | assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} | |
857 | end |
|
866 | end | |
858 |
|
867 | |||
859 | def test_index_with_issue_tracker_column |
|
868 | def test_index_with_issue_tracker_column | |
860 | issue = Issue.generate!(:project_id => 1, :tracker_id => 2) |
|
869 | issue = Issue.generate!(:project_id => 1, :tracker_id => 2) | |
861 | entry = TimeEntry.generate!(:issue => issue) |
|
870 | entry = TimeEntry.generate!(:issue => issue) | |
862 |
|
871 | |||
863 | get :index, :params => { |
|
872 | get :index, :params => { | |
864 | :c => %w(project spent_on issue comments hours issue.tracker) |
|
873 | :c => %w(project spent_on issue comments hours issue.tracker) | |
865 | } |
|
874 | } | |
866 | assert_response :success |
|
875 | assert_response :success | |
867 | assert_select 'td.issue-tracker', :text => issue.tracker.name |
|
876 | assert_select 'td.issue-tracker', :text => issue.tracker.name | |
868 | end |
|
877 | end | |
869 |
|
878 | |||
870 | def test_index_with_issue_tracker_sort |
|
879 | def test_index_with_issue_tracker_sort | |
871 | TimeEntry.delete_all |
|
880 | TimeEntry.delete_all | |
872 | TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 1)) |
|
881 | TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 1)) | |
873 | TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 3)) |
|
882 | TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 3)) | |
874 | TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 2)) |
|
883 | TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 2)) | |
875 | TimeEntry.generate!(:project_id => 1) |
|
884 | TimeEntry.generate!(:project_id => 1) | |
876 |
|
885 | |||
877 | get :index, :params => { |
|
886 | get :index, :params => { | |
878 | :c => ["hours", 'issue.tracker'], |
|
887 | :c => ["hours", 'issue.tracker'], | |
879 | :sort => 'issue.tracker' |
|
888 | :sort => 'issue.tracker' | |
880 | } |
|
889 | } | |
881 | assert_response :success |
|
890 | assert_response :success | |
882 |
|
891 | |||
883 | # Make sure that values are properly sorted |
|
892 | # Make sure that values are properly sorted | |
884 | values = css_select("td.issue-tracker").map(&:text).reject(&:blank?) |
|
893 | values = css_select("td.issue-tracker").map(&:text).reject(&:blank?) | |
885 | assert_equal Tracker.where(:id => [1, 2, 3]).sorted.pluck(:name), values |
|
894 | assert_equal Tracker.where(:id => [1, 2, 3]).sorted.pluck(:name), values | |
886 | end |
|
895 | end | |
887 |
|
896 | |||
888 | def test_index_with_filter_on_issue_custom_field |
|
897 | def test_index_with_filter_on_issue_custom_field | |
889 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) |
|
898 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) | |
890 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) |
|
899 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) | |
891 |
|
900 | |||
892 | get :index, :params => { |
|
901 | get :index, :params => { | |
893 | :f => ['issue.cf_2'], |
|
902 | :f => ['issue.cf_2'], | |
894 | :op => {'issue.cf_2' => '='}, |
|
903 | :op => {'issue.cf_2' => '='}, | |
895 | :v => {'issue.cf_2' => ['filter_on_issue_custom_field']} |
|
904 | :v => {'issue.cf_2' => ['filter_on_issue_custom_field']} | |
896 | } |
|
905 | } | |
897 | assert_response :success |
|
906 | assert_response :success | |
898 | assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} |
|
907 | assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} | |
899 | end |
|
908 | end | |
900 |
|
909 | |||
901 | def test_index_with_issue_custom_field_column |
|
910 | def test_index_with_issue_custom_field_column | |
902 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) |
|
911 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) | |
903 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) |
|
912 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) | |
904 |
|
913 | |||
905 | get :index, :params => { |
|
914 | get :index, :params => { | |
906 | :c => %w(project spent_on issue comments hours issue.cf_2) |
|
915 | :c => %w(project spent_on issue comments hours issue.cf_2) | |
907 | } |
|
916 | } | |
908 | assert_response :success |
|
917 | assert_response :success | |
909 | assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' |
|
918 | assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' | |
910 | end |
|
919 | end | |
911 |
|
920 | |||
912 | def test_index_with_time_entry_custom_field_column |
|
921 | def test_index_with_time_entry_custom_field_column | |
913 | field = TimeEntryCustomField.generate!(:field_format => 'string') |
|
922 | field = TimeEntryCustomField.generate!(:field_format => 'string') | |
914 | entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'}) |
|
923 | entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'}) | |
915 | field_name = "cf_#{field.id}" |
|
924 | field_name = "cf_#{field.id}" | |
916 |
|
925 | |||
917 | get :index, :params => { |
|
926 | get :index, :params => { | |
918 | :c => ["hours", field_name] |
|
927 | :c => ["hours", field_name] | |
919 | } |
|
928 | } | |
920 | assert_response :success |
|
929 | assert_response :success | |
921 | assert_select "td.#{field_name}", :text => 'CF Value' |
|
930 | assert_select "td.#{field_name}", :text => 'CF Value' | |
922 | end |
|
931 | end | |
923 |
|
932 | |||
924 | def test_index_with_time_entry_custom_field_sorting |
|
933 | def test_index_with_time_entry_custom_field_sorting | |
925 | field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field') |
|
934 | field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field') | |
926 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'}) |
|
935 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'}) | |
927 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'}) |
|
936 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'}) | |
928 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'}) |
|
937 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'}) | |
929 | field_name = "cf_#{field.id}" |
|
938 | field_name = "cf_#{field.id}" | |
930 |
|
939 | |||
931 | get :index, :params => { |
|
940 | get :index, :params => { | |
932 | :c => ["hours", field_name], |
|
941 | :c => ["hours", field_name], | |
933 | :sort => field_name |
|
942 | :sort => field_name | |
934 | } |
|
943 | } | |
935 | assert_response :success |
|
944 | assert_response :success | |
936 | assert_select "th a.sort", :text => 'String Field' |
|
945 | assert_select "th a.sort", :text => 'String Field' | |
937 |
|
946 | |||
938 | # Make sure that values are properly sorted |
|
947 | # Make sure that values are properly sorted | |
939 | values = css_select("td.#{field_name}").map(&:text).reject(&:blank?) |
|
948 | values = css_select("td.#{field_name}").map(&:text).reject(&:blank?) | |
940 | assert_equal values.sort, values |
|
949 | assert_equal values.sort, values | |
941 | assert_equal 3, values.size |
|
950 | assert_equal 3, values.size | |
942 | end |
|
951 | end | |
943 |
|
952 | |||
944 | def test_index_with_query |
|
953 | def test_index_with_query | |
945 | query = TimeEntryQuery.new(:project_id => 1, :name => 'Time Entry Query', :visibility => 2) |
|
954 | query = TimeEntryQuery.new(:project_id => 1, :name => 'Time Entry Query', :visibility => 2) | |
946 | query.save! |
|
955 | query.save! | |
947 | @request.session[:user_id] = 2 |
|
956 | @request.session[:user_id] = 2 | |
948 |
|
957 | |||
949 | get :index, :params => {:project_id => 'ecookbook', :query_id => query.id} |
|
958 | get :index, :params => {:project_id => 'ecookbook', :query_id => query.id} | |
950 | assert_response :success |
|
959 | assert_response :success | |
951 | assert_select 'h2', :text => query.name |
|
960 | assert_select 'h2', :text => query.name | |
952 | assert_select '#sidebar a.selected', :text => query.name |
|
961 | assert_select '#sidebar a.selected', :text => query.name | |
953 | end |
|
962 | end | |
954 |
|
963 | |||
955 | def test_index_atom_feed |
|
964 | def test_index_atom_feed | |
956 | get :index, :params => {:project_id => 1, :format => 'atom'} |
|
965 | get :index, :params => {:project_id => 1, :format => 'atom'} | |
957 | assert_response :success |
|
966 | assert_response :success | |
958 | assert_equal 'application/atom+xml', @response.content_type |
|
967 | assert_equal 'application/atom+xml', @response.content_type | |
959 | assert_select 'entry > title', :text => /7\.65 hours/ |
|
968 | assert_select 'entry > title', :text => /7\.65 hours/ | |
960 | end |
|
969 | end | |
961 |
|
970 | |||
962 | def test_index_at_project_level_should_include_csv_export_dialog |
|
971 | def test_index_at_project_level_should_include_csv_export_dialog | |
963 | get :index, :params => { |
|
972 | get :index, :params => { | |
964 | :project_id => 'ecookbook', |
|
973 | :project_id => 'ecookbook', | |
965 | :f => ['spent_on'], |
|
974 | :f => ['spent_on'], | |
966 | :op => {'spent_on' => '>='}, |
|
975 | :op => {'spent_on' => '>='}, | |
967 | :v => {'spent_on' => ['2007-04-01']}, |
|
976 | :v => {'spent_on' => ['2007-04-01']}, | |
968 | :c => ['spent_on', 'user'] |
|
977 | :c => ['spent_on', 'user'] | |
969 | } |
|
978 | } | |
970 | assert_response :success |
|
979 | assert_response :success | |
971 |
|
980 | |||
972 | assert_select '#csv-export-options' do |
|
981 | assert_select '#csv-export-options' do | |
973 | assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do |
|
982 | assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do | |
974 | # filter |
|
983 | # filter | |
975 | assert_select 'input[name=?][value=?]', 'f[]', 'spent_on' |
|
984 | assert_select 'input[name=?][value=?]', 'f[]', 'spent_on' | |
976 | assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' |
|
985 | assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' | |
977 | assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' |
|
986 | assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' | |
978 | # columns |
|
987 | # columns | |
979 | assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' |
|
988 | assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' | |
980 | assert_select 'input[name=?][value=?]', 'c[]', 'user' |
|
989 | assert_select 'input[name=?][value=?]', 'c[]', 'user' | |
981 | assert_select 'input[name=?]', 'c[]', 2 |
|
990 | assert_select 'input[name=?]', 'c[]', 2 | |
982 | end |
|
991 | end | |
983 | end |
|
992 | end | |
984 | end |
|
993 | end | |
985 |
|
994 | |||
986 | def test_index_cross_project_should_include_csv_export_dialog |
|
995 | def test_index_cross_project_should_include_csv_export_dialog | |
987 | get :index |
|
996 | get :index | |
988 | assert_response :success |
|
997 | assert_response :success | |
989 |
|
998 | |||
990 | assert_select '#csv-export-options' do |
|
999 | assert_select '#csv-export-options' do | |
991 | assert_select 'form[action=?][method=get]', '/time_entries.csv' |
|
1000 | assert_select 'form[action=?][method=get]', '/time_entries.csv' | |
992 | end |
|
1001 | end | |
993 | end |
|
1002 | end | |
994 |
|
1003 | |||
995 | def test_index_csv_all_projects |
|
1004 | def test_index_csv_all_projects | |
996 | with_settings :date_format => '%m/%d/%Y' do |
|
1005 | with_settings :date_format => '%m/%d/%Y' do | |
997 | get :index, :params => {:format => 'csv'} |
|
1006 | get :index, :params => {:format => 'csv'} | |
998 | assert_response :success |
|
1007 | assert_response :success | |
999 | assert_equal 'text/csv; header=present', response.content_type |
|
1008 | assert_equal 'text/csv; header=present', response.content_type | |
1000 | end |
|
1009 | end | |
1001 | end |
|
1010 | end | |
1002 |
|
1011 | |||
1003 | def test_index_csv |
|
1012 | def test_index_csv | |
1004 | with_settings :date_format => '%m/%d/%Y' do |
|
1013 | with_settings :date_format => '%m/%d/%Y' do | |
1005 | get :index, :params => {:project_id => 1, :format => 'csv'} |
|
1014 | get :index, :params => {:project_id => 1, :format => 'csv'} | |
1006 | assert_response :success |
|
1015 | assert_response :success | |
1007 | assert_equal 'text/csv; header=present', response.content_type |
|
1016 | assert_equal 'text/csv; header=present', response.content_type | |
1008 | end |
|
1017 | end | |
1009 | end |
|
1018 | end | |
1010 |
|
1019 | |||
1011 | def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject |
|
1020 | def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject | |
1012 | issue = Issue.find(1) |
|
1021 | issue = Issue.find(1) | |
1013 | entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test") |
|
1022 | entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test") | |
1014 |
|
1023 | |||
1015 | get :index, :params => {:format => 'csv'} |
|
1024 | get :index, :params => {:format => 'csv'} | |
1016 | line = response.body.split("\n").detect {|l| l.include?(entry.comments)} |
|
1025 | line = response.body.split("\n").detect {|l| l.include?(entry.comments)} | |
1017 | assert_not_nil line |
|
1026 | assert_not_nil line | |
1018 | assert_include "#{issue.tracker} #1: #{issue.subject}", line |
|
1027 | assert_include "#{issue.tracker} #1: #{issue.subject}", line | |
1019 | end |
|
1028 | end | |
1020 | end |
|
1029 | end |
General Comments 0
You need to be logged in to leave comments.
Login now