##// END OF EJS Templates
Merged r3009 from trunk....
Eric Davis -
r2932:3d926660ba01
parent child
Show More
@@ -1,293 +1,293
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class TimelogController < ApplicationController
19 19 menu_item :issues
20 20 before_filter :find_project, :authorize, :only => [:edit, :destroy]
21 21 before_filter :find_optional_project, :only => [:report, :details]
22 22
23 23 verify :method => :post, :only => :destroy, :redirect_to => { :action => :details }
24 24
25 25 helper :sort
26 26 include SortHelper
27 27 helper :issues
28 28 include TimelogHelper
29 29 helper :custom_fields
30 30 include CustomFieldsHelper
31 31
32 32 def report
33 33 @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
34 34 :klass => Project,
35 35 :label => :label_project},
36 36 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
37 37 :klass => Version,
38 38 :label => :label_version},
39 39 'category' => {:sql => "#{Issue.table_name}.category_id",
40 40 :klass => IssueCategory,
41 41 :label => :field_category},
42 42 'member' => {:sql => "#{TimeEntry.table_name}.user_id",
43 43 :klass => User,
44 44 :label => :label_member},
45 45 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
46 46 :klass => Tracker,
47 47 :label => :label_tracker},
48 48 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
49 49 :klass => Enumeration,
50 50 :label => :label_activity},
51 51 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
52 52 :klass => Issue,
53 53 :label => :label_issue}
54 54 }
55 55
56 56 # Add list and boolean custom fields as available criterias
57 57 custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields)
58 58 custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
59 59 @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id)",
60 60 :format => cf.field_format,
61 61 :label => cf.name}
62 62 end if @project
63 63
64 64 # Add list and boolean time entry custom fields
65 65 TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
66 66 @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id)",
67 67 :format => cf.field_format,
68 68 :label => cf.name}
69 69 end
70 70
71 71 @criterias = params[:criterias] || []
72 72 @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
73 73 @criterias.uniq!
74 74 @criterias = @criterias[0,3]
75 75
76 76 @columns = (params[:columns] && %w(year month week day).include?(params[:columns])) ? params[:columns] : 'month'
77 77
78 78 retrieve_date_range
79 79
80 80 unless @criterias.empty?
81 81 sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
82 82 sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
83 83
84 84 sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
85 85 sql << " FROM #{TimeEntry.table_name}"
86 86 sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
87 87 sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
88 88 sql << " WHERE"
89 89 sql << " (%s) AND" % @project.project_condition(Setting.display_subprojects_issues?) if @project
90 90 sql << " (%s) AND" % Project.allowed_to_condition(User.current, :view_time_entries)
91 sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
91 sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from), ActiveRecord::Base.connection.quoted_date(@to)]
92 92 sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
93 93
94 94 @hours = ActiveRecord::Base.connection.select_all(sql)
95 95
96 96 @hours.each do |row|
97 97 case @columns
98 98 when 'year'
99 99 row['year'] = row['tyear']
100 100 when 'month'
101 101 row['month'] = "#{row['tyear']}-#{row['tmonth']}"
102 102 when 'week'
103 103 row['week'] = "#{row['tyear']}-#{row['tweek']}"
104 104 when 'day'
105 105 row['day'] = "#{row['spent_on']}"
106 106 end
107 107 end
108 108
109 109 @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
110 110
111 111 @periods = []
112 112 # Date#at_beginning_of_ not supported in Rails 1.2.x
113 113 date_from = @from.to_time
114 114 # 100 columns max
115 115 while date_from <= @to.to_time && @periods.length < 100
116 116 case @columns
117 117 when 'year'
118 118 @periods << "#{date_from.year}"
119 119 date_from = (date_from + 1.year).at_beginning_of_year
120 120 when 'month'
121 121 @periods << "#{date_from.year}-#{date_from.month}"
122 122 date_from = (date_from + 1.month).at_beginning_of_month
123 123 when 'week'
124 124 @periods << "#{date_from.year}-#{date_from.to_date.cweek}"
125 125 date_from = (date_from + 7.day).at_beginning_of_week
126 126 when 'day'
127 127 @periods << "#{date_from.to_date}"
128 128 date_from = date_from + 1.day
129 129 end
130 130 end
131 131 end
132 132
133 133 respond_to do |format|
134 134 format.html { render :layout => !request.xhr? }
135 135 format.csv { send_data(report_to_csv(@criterias, @periods, @hours).read, :type => 'text/csv; header=present', :filename => 'timelog.csv') }
136 136 end
137 137 end
138 138
139 139 def details
140 140 sort_init 'spent_on', 'desc'
141 141 sort_update 'spent_on' => 'spent_on',
142 142 'user' => 'user_id',
143 143 'activity' => 'activity_id',
144 144 'project' => "#{Project.table_name}.name",
145 145 'issue' => 'issue_id',
146 146 'hours' => 'hours'
147 147
148 148 cond = ARCondition.new
149 149 if @project.nil?
150 150 cond << Project.allowed_to_condition(User.current, :view_time_entries)
151 151 elsif @issue.nil?
152 152 cond << @project.project_condition(Setting.display_subprojects_issues?)
153 153 else
154 154 cond << ["#{TimeEntry.table_name}.issue_id = ?", @issue.id]
155 155 end
156 156
157 157 retrieve_date_range
158 158 cond << ['spent_on BETWEEN ? AND ?', @from, @to]
159 159
160 160 TimeEntry.visible_by(User.current) do
161 161 respond_to do |format|
162 162 format.html {
163 163 # Paginate results
164 164 @entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions)
165 165 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
166 166 @entries = TimeEntry.find(:all,
167 167 :include => [:project, :activity, :user, {:issue => :tracker}],
168 168 :conditions => cond.conditions,
169 169 :order => sort_clause,
170 170 :limit => @entry_pages.items_per_page,
171 171 :offset => @entry_pages.current.offset)
172 172 @total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
173 173
174 174 render :layout => !request.xhr?
175 175 }
176 176 format.atom {
177 177 entries = TimeEntry.find(:all,
178 178 :include => [:project, :activity, :user, {:issue => :tracker}],
179 179 :conditions => cond.conditions,
180 180 :order => "#{TimeEntry.table_name}.created_on DESC",
181 181 :limit => Setting.feeds_limit.to_i)
182 182 render_feed(entries, :title => l(:label_spent_time))
183 183 }
184 184 format.csv {
185 185 # Export all entries
186 186 @entries = TimeEntry.find(:all,
187 187 :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
188 188 :conditions => cond.conditions,
189 189 :order => sort_clause)
190 190 send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
191 191 }
192 192 end
193 193 end
194 194 end
195 195
196 196 def edit
197 197 render_403 and return if @time_entry && !@time_entry.editable_by?(User.current)
198 198 @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
199 199 @time_entry.attributes = params[:time_entry]
200 200
201 201 call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
202 202
203 203 if request.post? and @time_entry.save
204 204 flash[:notice] = l(:notice_successful_update)
205 205 redirect_back_or_default :action => 'details', :project_id => @time_entry.project
206 206 return
207 207 end
208 208 end
209 209
210 210 def destroy
211 211 render_404 and return unless @time_entry
212 212 render_403 and return unless @time_entry.editable_by?(User.current)
213 213 @time_entry.destroy
214 214 flash[:notice] = l(:notice_successful_delete)
215 215 redirect_to :back
216 216 rescue ::ActionController::RedirectBackError
217 217 redirect_to :action => 'details', :project_id => @time_entry.project
218 218 end
219 219
220 220 private
221 221 def find_project
222 222 if params[:id]
223 223 @time_entry = TimeEntry.find(params[:id])
224 224 @project = @time_entry.project
225 225 elsif params[:issue_id]
226 226 @issue = Issue.find(params[:issue_id])
227 227 @project = @issue.project
228 228 elsif params[:project_id]
229 229 @project = Project.find(params[:project_id])
230 230 else
231 231 render_404
232 232 return false
233 233 end
234 234 rescue ActiveRecord::RecordNotFound
235 235 render_404
236 236 end
237 237
238 238 def find_optional_project
239 239 if !params[:issue_id].blank?
240 240 @issue = Issue.find(params[:issue_id])
241 241 @project = @issue.project
242 242 elsif !params[:project_id].blank?
243 243 @project = Project.find(params[:project_id])
244 244 end
245 245 deny_access unless User.current.allowed_to?(:view_time_entries, @project, :global => true)
246 246 end
247 247
248 248 # Retrieves the date range based on predefined ranges or specific from/to param dates
249 249 def retrieve_date_range
250 250 @free_period = false
251 251 @from, @to = nil, nil
252 252
253 253 if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?)
254 254 case params[:period].to_s
255 255 when 'today'
256 256 @from = @to = Date.today
257 257 when 'yesterday'
258 258 @from = @to = Date.today - 1
259 259 when 'current_week'
260 260 @from = Date.today - (Date.today.cwday - 1)%7
261 261 @to = @from + 6
262 262 when 'last_week'
263 263 @from = Date.today - 7 - (Date.today.cwday - 1)%7
264 264 @to = @from + 6
265 265 when '7_days'
266 266 @from = Date.today - 7
267 267 @to = Date.today
268 268 when 'current_month'
269 269 @from = Date.civil(Date.today.year, Date.today.month, 1)
270 270 @to = (@from >> 1) - 1
271 271 when 'last_month'
272 272 @from = Date.civil(Date.today.year, Date.today.month, 1) << 1
273 273 @to = (@from >> 1) - 1
274 274 when '30_days'
275 275 @from = Date.today - 30
276 276 @to = Date.today
277 277 when 'current_year'
278 278 @from = Date.civil(Date.today.year, 1, 1)
279 279 @to = Date.civil(Date.today.year, 12, 31)
280 280 end
281 281 elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?))
282 282 begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end
283 283 begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end
284 284 @free_period = true
285 285 else
286 286 # default
287 287 end
288 288
289 289 @from, @to = @to, @from if @from && @to && @from > @to
290 290 @from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1
291 291 @to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today)
292 292 end
293 293 end
@@ -1,278 +1,294
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'timelog_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class TimelogController; def rescue_action(e) raise e end; end
23 23
24 24 class TimelogControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values
26 26
27 27 def setup
28 28 @controller = TimelogController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 end
32 32
33 33 def test_get_edit
34 34 @request.session[:user_id] = 3
35 35 get :edit, :project_id => 1
36 36 assert_response :success
37 37 assert_template 'edit'
38 38 # Default activity selected
39 39 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
40 40 :content => 'Development'
41 41 end
42 42
43 43 def test_post_edit
44 44 @request.session[:user_id] = 3
45 45 post :edit, :project_id => 1,
46 46 :time_entry => {:comments => 'Some work on TimelogControllerTest',
47 47 # Not the default activity
48 48 :activity_id => '11',
49 49 :spent_on => '2008-03-14',
50 50 :issue_id => '1',
51 51 :hours => '7.3'}
52 52 assert_redirected_to 'projects/ecookbook/timelog/details'
53 53
54 54 i = Issue.find(1)
55 55 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
56 56 assert_not_nil t
57 57 assert_equal 11, t.activity_id
58 58 assert_equal 7.3, t.hours
59 59 assert_equal 3, t.user_id
60 60 assert_equal i, t.issue
61 61 assert_equal i.project, t.project
62 62 end
63 63
64 64 def test_update
65 65 entry = TimeEntry.find(1)
66 66 assert_equal 1, entry.issue_id
67 67 assert_equal 2, entry.user_id
68 68
69 69 @request.session[:user_id] = 1
70 70 post :edit, :id => 1,
71 71 :time_entry => {:issue_id => '2',
72 72 :hours => '8'}
73 73 assert_redirected_to 'projects/ecookbook/timelog/details'
74 74 entry.reload
75 75
76 76 assert_equal 8, entry.hours
77 77 assert_equal 2, entry.issue_id
78 78 assert_equal 2, entry.user_id
79 79 end
80 80
81 81 def test_destroy
82 82 @request.session[:user_id] = 2
83 83 post :destroy, :id => 1
84 84 assert_redirected_to 'projects/ecookbook/timelog/details'
85 85 assert_nil TimeEntry.find_by_id(1)
86 86 end
87 87
88 88 def test_report_no_criteria
89 89 get :report, :project_id => 1
90 90 assert_response :success
91 91 assert_template 'report'
92 92 end
93 93
94 94 def test_report_all_projects
95 95 get :report
96 96 assert_response :success
97 97 assert_template 'report'
98 98 end
99 99
100 100 def test_report_all_projects_denied
101 101 r = Role.anonymous
102 102 r.permissions.delete(:view_time_entries)
103 103 r.permissions_will_change!
104 104 r.save
105 105 get :report
106 106 assert_redirected_to '/account/login'
107 107 end
108 108
109 109 def test_report_all_projects_one_criteria
110 110 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
111 111 assert_response :success
112 112 assert_template 'report'
113 113 assert_not_nil assigns(:total_hours)
114 114 assert_equal "8.65", "%.2f" % assigns(:total_hours)
115 115 end
116 116
117 117 def test_report_all_time
118 118 get :report, :project_id => 1, :criterias => ['project', 'issue']
119 119 assert_response :success
120 120 assert_template 'report'
121 121 assert_not_nil assigns(:total_hours)
122 122 assert_equal "162.90", "%.2f" % assigns(:total_hours)
123 123 end
124 124
125 125 def test_report_all_time_by_day
126 126 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
127 127 assert_response :success
128 128 assert_template 'report'
129 129 assert_not_nil assigns(:total_hours)
130 130 assert_equal "162.90", "%.2f" % assigns(:total_hours)
131 131 assert_tag :tag => 'th', :content => '2007-03-12'
132 132 end
133 133
134 134 def test_report_one_criteria
135 135 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
136 136 assert_response :success
137 137 assert_template 'report'
138 138 assert_not_nil assigns(:total_hours)
139 139 assert_equal "8.65", "%.2f" % assigns(:total_hours)
140 140 end
141 141
142 142 def test_report_two_criterias
143 143 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
144 144 assert_response :success
145 145 assert_template 'report'
146 146 assert_not_nil assigns(:total_hours)
147 147 assert_equal "162.90", "%.2f" % assigns(:total_hours)
148 148 end
149 149
150 def test_report_one_day
151 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"]
152 assert_response :success
153 assert_template 'report'
154 assert_not_nil assigns(:total_hours)
155 assert_equal "4.25", "%.2f" % assigns(:total_hours)
156 end
157
150 158 def test_report_custom_field_criteria
151 159 get :report, :project_id => 1, :criterias => ['project', 'cf_1']
152 160 assert_response :success
153 161 assert_template 'report'
154 162 assert_not_nil assigns(:total_hours)
155 163 assert_not_nil assigns(:criterias)
156 164 assert_equal 2, assigns(:criterias).size
157 165 assert_equal "162.90", "%.2f" % assigns(:total_hours)
158 166 # Custom field column
159 167 assert_tag :tag => 'th', :content => 'Database'
160 168 # Custom field row
161 169 assert_tag :tag => 'td', :content => 'MySQL',
162 170 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
163 171 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
164 172 :content => '1' }}
165 173 end
166 174
167 175 def test_report_one_criteria_no_result
168 176 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
169 177 assert_response :success
170 178 assert_template 'report'
171 179 assert_not_nil assigns(:total_hours)
172 180 assert_equal "0.00", "%.2f" % assigns(:total_hours)
173 181 end
174 182
175 183 def test_report_all_projects_csv_export
176 184 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
177 185 assert_response :success
178 186 assert_equal 'text/csv', @response.content_type
179 187 lines = @response.body.chomp.split("\n")
180 188 # Headers
181 189 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
182 190 # Total row
183 191 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
184 192 end
185 193
186 194 def test_report_csv_export
187 195 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
188 196 assert_response :success
189 197 assert_equal 'text/csv', @response.content_type
190 198 lines = @response.body.chomp.split("\n")
191 199 # Headers
192 200 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
193 201 # Total row
194 202 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
195 203 end
196 204
197 205 def test_details_all_projects
198 206 get :details
199 207 assert_response :success
200 208 assert_template 'details'
201 209 assert_not_nil assigns(:total_hours)
202 210 assert_equal "162.90", "%.2f" % assigns(:total_hours)
203 211 end
204 212
205 213 def test_details_at_project_level
206 214 get :details, :project_id => 1
207 215 assert_response :success
208 216 assert_template 'details'
209 217 assert_not_nil assigns(:entries)
210 218 assert_equal 4, assigns(:entries).size
211 219 # project and subproject
212 220 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
213 221 assert_not_nil assigns(:total_hours)
214 222 assert_equal "162.90", "%.2f" % assigns(:total_hours)
215 223 # display all time by default
216 224 assert_equal '2007-03-11'.to_date, assigns(:from)
217 225 assert_equal '2007-04-22'.to_date, assigns(:to)
218 226 end
219 227
220 228 def test_details_at_project_level_with_date_range
221 229 get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
222 230 assert_response :success
223 231 assert_template 'details'
224 232 assert_not_nil assigns(:entries)
225 233 assert_equal 3, assigns(:entries).size
226 234 assert_not_nil assigns(:total_hours)
227 235 assert_equal "12.90", "%.2f" % assigns(:total_hours)
228 236 assert_equal '2007-03-20'.to_date, assigns(:from)
229 237 assert_equal '2007-04-30'.to_date, assigns(:to)
230 238 end
231 239
232 240 def test_details_at_project_level_with_period
233 241 get :details, :project_id => 1, :period => '7_days'
234 242 assert_response :success
235 243 assert_template 'details'
236 244 assert_not_nil assigns(:entries)
237 245 assert_not_nil assigns(:total_hours)
238 246 assert_equal Date.today - 7, assigns(:from)
239 247 assert_equal Date.today, assigns(:to)
240 248 end
249
250 def test_details_one_day
251 get :details, :project_id => 1, :from => "2007-03-23", :to => "2007-03-23"
252 assert_response :success
253 assert_template 'details'
254 assert_not_nil assigns(:total_hours)
255 assert_equal "4.25", "%.2f" % assigns(:total_hours)
256 end
241 257
242 258 def test_details_at_issue_level
243 259 get :details, :issue_id => 1
244 260 assert_response :success
245 261 assert_template 'details'
246 262 assert_not_nil assigns(:entries)
247 263 assert_equal 2, assigns(:entries).size
248 264 assert_not_nil assigns(:total_hours)
249 265 assert_equal 154.25, assigns(:total_hours)
250 266 # display all time by default
251 267 assert_equal '2007-03-11'.to_date, assigns(:from)
252 268 assert_equal '2007-04-22'.to_date, assigns(:to)
253 269 end
254 270
255 271 def test_details_atom_feed
256 272 get :details, :project_id => 1, :format => 'atom'
257 273 assert_response :success
258 274 assert_equal 'application/atom+xml', @response.content_type
259 275 assert_not_nil assigns(:items)
260 276 assert assigns(:items).first.is_a?(TimeEntry)
261 277 end
262 278
263 279 def test_details_all_projects_csv_export
264 280 get :details, :format => 'csv'
265 281 assert_response :success
266 282 assert_equal 'text/csv', @response.content_type
267 283 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
268 284 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
269 285 end
270 286
271 287 def test_details_csv_export
272 288 get :details, :project_id => 1, :format => 'csv'
273 289 assert_response :success
274 290 assert_equal 'text/csv', @response.content_type
275 291 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
276 292 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
277 293 end
278 294 end
General Comments 0
You need to be logged in to leave comments. Login now