##// END OF EJS Templates
Adds atom feed on time entries details (#1479)....
Jean-Philippe Lang -
r1546:062a2d6f5d6e
parent child
Show More
@@ -1,254 +1,262
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 layout 'base'
20 20 menu_item :issues
21 21 before_filter :find_project, :authorize
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 @project.all_custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
58 58 @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM custom_values c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = issues.id)",
59 59 :format => cf.field_format,
60 60 :label => cf.name}
61 61 end
62 62
63 63 @criterias = params[:criterias] || []
64 64 @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
65 65 @criterias.uniq!
66 66 @criterias = @criterias[0,3]
67 67
68 68 @columns = (params[:columns] && %w(year month week day).include?(params[:columns])) ? params[:columns] : 'month'
69 69
70 70 retrieve_date_range
71 71
72 72 unless @criterias.empty?
73 73 sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
74 74 sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
75 75
76 76 sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
77 77 sql << " FROM #{TimeEntry.table_name}"
78 78 sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
79 79 sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
80 80 sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?)
81 81 sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
82 82 sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
83 83 sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
84 84
85 85 @hours = ActiveRecord::Base.connection.select_all(sql)
86 86
87 87 @hours.each do |row|
88 88 case @columns
89 89 when 'year'
90 90 row['year'] = row['tyear']
91 91 when 'month'
92 92 row['month'] = "#{row['tyear']}-#{row['tmonth']}"
93 93 when 'week'
94 94 row['week'] = "#{row['tyear']}-#{row['tweek']}"
95 95 when 'day'
96 96 row['day'] = "#{row['spent_on']}"
97 97 end
98 98 end
99 99
100 100 @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
101 101
102 102 @periods = []
103 103 # Date#at_beginning_of_ not supported in Rails 1.2.x
104 104 date_from = @from.to_time
105 105 # 100 columns max
106 106 while date_from <= @to.to_time && @periods.length < 100
107 107 case @columns
108 108 when 'year'
109 109 @periods << "#{date_from.year}"
110 110 date_from = (date_from + 1.year).at_beginning_of_year
111 111 when 'month'
112 112 @periods << "#{date_from.year}-#{date_from.month}"
113 113 date_from = (date_from + 1.month).at_beginning_of_month
114 114 when 'week'
115 115 @periods << "#{date_from.year}-#{date_from.to_date.cweek}"
116 116 date_from = (date_from + 7.day).at_beginning_of_week
117 117 when 'day'
118 118 @periods << "#{date_from.to_date}"
119 119 date_from = date_from + 1.day
120 120 end
121 121 end
122 122 end
123 123
124 124 respond_to do |format|
125 125 format.html { render :layout => !request.xhr? }
126 126 format.csv { send_data(report_to_csv(@criterias, @periods, @hours).read, :type => 'text/csv; header=present', :filename => 'timelog.csv') }
127 127 end
128 128 end
129 129
130 130 def details
131 131 sort_init 'spent_on', 'desc'
132 132 sort_update
133 133
134 134 cond = ARCondition.new
135 135 cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) :
136 136 ["#{TimeEntry.table_name}.issue_id = ?", @issue.id])
137 137
138 138 retrieve_date_range
139 139 cond << ['spent_on BETWEEN ? AND ?', @from, @to]
140 140
141 141 TimeEntry.visible_by(User.current) do
142 142 respond_to do |format|
143 143 format.html {
144 144 # Paginate results
145 145 @entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions)
146 146 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
147 147 @entries = TimeEntry.find(:all,
148 148 :include => [:project, :activity, :user, {:issue => :tracker}],
149 149 :conditions => cond.conditions,
150 150 :order => sort_clause,
151 151 :limit => @entry_pages.items_per_page,
152 152 :offset => @entry_pages.current.offset)
153 153 @total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
154 154
155 155 render :layout => !request.xhr?
156 156 }
157 format.atom {
158 entries = TimeEntry.find(:all,
159 :include => [:project, :activity, :user, {:issue => :tracker}],
160 :conditions => cond.conditions,
161 :order => "#{TimeEntry.table_name}.created_on DESC",
162 :limit => Setting.feeds_limit.to_i)
163 render_feed(entries, :title => l(:label_spent_time))
164 }
157 165 format.csv {
158 166 # Export all entries
159 167 @entries = TimeEntry.find(:all,
160 168 :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
161 169 :conditions => cond.conditions,
162 170 :order => sort_clause)
163 171 send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
164 172 }
165 173 end
166 174 end
167 175 end
168 176
169 177 def edit
170 178 render_403 and return if @time_entry && !@time_entry.editable_by?(User.current)
171 179 @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
172 180 @time_entry.attributes = params[:time_entry]
173 181 if request.post? and @time_entry.save
174 182 flash[:notice] = l(:notice_successful_update)
175 183 redirect_to(params[:back_url] || {:action => 'details', :project_id => @time_entry.project})
176 184 return
177 185 end
178 186 @activities = Enumeration::get_values('ACTI')
179 187 end
180 188
181 189 def destroy
182 190 render_404 and return unless @time_entry
183 191 render_403 and return unless @time_entry.editable_by?(User.current)
184 192 @time_entry.destroy
185 193 flash[:notice] = l(:notice_successful_delete)
186 194 redirect_to :back
187 195 rescue RedirectBackError
188 196 redirect_to :action => 'details', :project_id => @time_entry.project
189 197 end
190 198
191 199 private
192 200 def find_project
193 201 if params[:id]
194 202 @time_entry = TimeEntry.find(params[:id])
195 203 @project = @time_entry.project
196 204 elsif params[:issue_id]
197 205 @issue = Issue.find(params[:issue_id])
198 206 @project = @issue.project
199 207 elsif params[:project_id]
200 208 @project = Project.find(params[:project_id])
201 209 else
202 210 render_404
203 211 return false
204 212 end
205 213 rescue ActiveRecord::RecordNotFound
206 214 render_404
207 215 end
208 216
209 217 # Retrieves the date range based on predefined ranges or specific from/to param dates
210 218 def retrieve_date_range
211 219 @free_period = false
212 220 @from, @to = nil, nil
213 221
214 222 if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?)
215 223 case params[:period].to_s
216 224 when 'today'
217 225 @from = @to = Date.today
218 226 when 'yesterday'
219 227 @from = @to = Date.today - 1
220 228 when 'current_week'
221 229 @from = Date.today - (Date.today.cwday - 1)%7
222 230 @to = @from + 6
223 231 when 'last_week'
224 232 @from = Date.today - 7 - (Date.today.cwday - 1)%7
225 233 @to = @from + 6
226 234 when '7_days'
227 235 @from = Date.today - 7
228 236 @to = Date.today
229 237 when 'current_month'
230 238 @from = Date.civil(Date.today.year, Date.today.month, 1)
231 239 @to = (@from >> 1) - 1
232 240 when 'last_month'
233 241 @from = Date.civil(Date.today.year, Date.today.month, 1) << 1
234 242 @to = (@from >> 1) - 1
235 243 when '30_days'
236 244 @from = Date.today - 30
237 245 @to = Date.today
238 246 when 'current_year'
239 247 @from = Date.civil(Date.today.year, 1, 1)
240 248 @to = Date.civil(Date.today.year, 12, 31)
241 249 end
242 250 elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?))
243 251 begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end
244 252 begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end
245 253 @free_period = true
246 254 else
247 255 # default
248 256 end
249 257
250 258 @from, @to = @to, @from if @from && @to && @from > @to
251 259 @from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today) - 1
252 260 @to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today)
253 261 end
254 262 end
@@ -1,73 +1,78
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 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 TimeEntry < ActiveRecord::Base
19 19 # could have used polymorphic association
20 20 # project association here allows easy loading of time entries at project level with one database trip
21 21 belongs_to :project
22 22 belongs_to :issue
23 23 belongs_to :user
24 24 belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id
25 25
26 26 attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
27 27
28 acts_as_event :title => Proc.new {|o| "#{o.user}: #{lwr(:label_f_hour, o.hours)} (#{(o.issue || o.project).event_title})"},
29 :url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project}},
30 :author => :user,
31 :description => :comments
32
28 33 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
29 34 validates_numericality_of :hours, :allow_nil => true
30 35 validates_length_of :comments, :maximum => 255
31 36
32 37 def after_initialize
33 38 if new_record? && self.activity.nil?
34 39 if default_activity = Enumeration.default('ACTI')
35 40 self.activity_id = default_activity.id
36 41 end
37 42 end
38 43 end
39 44
40 45 def before_validation
41 46 self.project = issue.project if issue && project.nil?
42 47 end
43 48
44 49 def validate
45 50 errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000)
46 51 errors.add :project_id, :activerecord_error_invalid if project.nil?
47 52 errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project)
48 53 end
49 54
50 55 def hours=(h)
51 56 write_attribute :hours, (h.is_a?(String) ? h.to_hours : h)
52 57 end
53 58
54 59 # tyear, tmonth, tweek assigned where setting spent_on attributes
55 60 # these attributes make time aggregations easier
56 61 def spent_on=(date)
57 62 super
58 63 self.tyear = spent_on ? spent_on.year : nil
59 64 self.tmonth = spent_on ? spent_on.month : nil
60 65 self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
61 66 end
62 67
63 68 # Returns true if the time entry can be edited by usr, otherwise false
64 69 def editable_by?(usr)
65 70 (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
66 71 end
67 72
68 73 def self.visible_by(usr)
69 74 with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
70 75 yield
71 76 end
72 77 end
73 78 end
@@ -1,31 +1,36
1 1 <div class="contextual">
2 2 <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %>
3 3 </div>
4 4
5 5 <h2><%= l(:label_spent_time) %></h2>
6 6
7 7 <% if @issue %>
8 8 <h3><%= link_to(@project.name, {:action => 'details', :project_id => @project}) %> / <%= link_to_issue(@issue) %></h3>
9 9 <% end %>
10 10
11 11 <% form_remote_tag( :url => {}, :method => :get, :update => 'content' ) do %>
12 12 <%= hidden_field_tag 'project_id', params[:project_id] %>
13 13 <%= hidden_field_tag 'issue_id', params[:issue_id] if @issue %>
14 14 <%= render :partial => 'date_range' %>
15 15 <% end %>
16 16
17 17 <div class="total-hours">
18 18 <p><%= l(:label_total) %>: <%= html_hours(lwr(:label_f_hour, @total_hours)) %></p>
19 19 </div>
20 20
21 21 <% unless @entries.empty? %>
22 22 <%= render :partial => 'list', :locals => { :entries => @entries }%>
23 23 <p class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></p>
24 24
25 25 <p class="other-formats">
26 26 <%= l(:label_export_to) %>
27 <span><%= link_to 'Atom', {:issue_id => @issue, :format => 'atom', :key => User.current.rss_key}, :class => 'feed' %></span>
27 28 <span><%= link_to 'CSV', params.merge(:format => 'csv'), :class => 'csv' %></span>
28 29 </p>
29 30 <% end %>
30 31
31 32 <% html_title l(:label_spent_time), l(:label_details) %>
33
34 <% content_for :header_tags do %>
35 <%= auto_discovery_link_tag(:atom, {:issue_id => @issue, :format => 'atom', :key => User.current.rss_key}, :title => l(:label_spent_time)) %>
36 <% end %>
@@ -1,220 +1,228
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 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_time
95 95 get :report, :project_id => 1, :criterias => ['project', 'issue']
96 96 assert_response :success
97 97 assert_template 'report'
98 98 assert_not_nil assigns(:total_hours)
99 99 assert_equal "162.90", "%.2f" % assigns(:total_hours)
100 100 end
101 101
102 102 def test_report_all_time_by_day
103 103 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
104 104 assert_response :success
105 105 assert_template 'report'
106 106 assert_not_nil assigns(:total_hours)
107 107 assert_equal "162.90", "%.2f" % assigns(:total_hours)
108 108 assert_tag :tag => 'th', :content => '2007-03-12'
109 109 end
110 110
111 111 def test_report_one_criteria
112 112 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
113 113 assert_response :success
114 114 assert_template 'report'
115 115 assert_not_nil assigns(:total_hours)
116 116 assert_equal "8.65", "%.2f" % assigns(:total_hours)
117 117 end
118 118
119 119 def test_report_two_criterias
120 120 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
121 121 assert_response :success
122 122 assert_template 'report'
123 123 assert_not_nil assigns(:total_hours)
124 124 assert_equal "162.90", "%.2f" % assigns(:total_hours)
125 125 end
126 126
127 127 def test_report_custom_field_criteria
128 128 get :report, :project_id => 1, :criterias => ['project', 'cf_1']
129 129 assert_response :success
130 130 assert_template 'report'
131 131 assert_not_nil assigns(:total_hours)
132 132 assert_not_nil assigns(:criterias)
133 133 assert_equal 2, assigns(:criterias).size
134 134 assert_equal "162.90", "%.2f" % assigns(:total_hours)
135 135 # Custom field column
136 136 assert_tag :tag => 'th', :content => 'Database'
137 137 # Custom field row
138 138 assert_tag :tag => 'td', :content => 'MySQL',
139 139 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
140 140 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
141 141 :content => '1' }}
142 142 end
143 143
144 144 def test_report_one_criteria_no_result
145 145 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
146 146 assert_response :success
147 147 assert_template 'report'
148 148 assert_not_nil assigns(:total_hours)
149 149 assert_equal "0.00", "%.2f" % assigns(:total_hours)
150 150 end
151 151
152 152 def test_report_csv_export
153 153 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
154 154 assert_response :success
155 155 assert_equal 'text/csv', @response.content_type
156 156 lines = @response.body.chomp.split("\n")
157 157 # Headers
158 158 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
159 159 # Total row
160 160 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
161 161 end
162 162
163 163 def test_details_at_project_level
164 164 get :details, :project_id => 1
165 165 assert_response :success
166 166 assert_template 'details'
167 167 assert_not_nil assigns(:entries)
168 168 assert_equal 4, assigns(:entries).size
169 169 # project and subproject
170 170 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
171 171 assert_not_nil assigns(:total_hours)
172 172 assert_equal "162.90", "%.2f" % assigns(:total_hours)
173 173 # display all time by default
174 174 assert_equal '2007-03-11'.to_date, assigns(:from)
175 175 assert_equal '2007-04-22'.to_date, assigns(:to)
176 176 end
177 177
178 178 def test_details_at_project_level_with_date_range
179 179 get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
180 180 assert_response :success
181 181 assert_template 'details'
182 182 assert_not_nil assigns(:entries)
183 183 assert_equal 3, assigns(:entries).size
184 184 assert_not_nil assigns(:total_hours)
185 185 assert_equal "12.90", "%.2f" % assigns(:total_hours)
186 186 assert_equal '2007-03-20'.to_date, assigns(:from)
187 187 assert_equal '2007-04-30'.to_date, assigns(:to)
188 188 end
189 189
190 190 def test_details_at_project_level_with_period
191 191 get :details, :project_id => 1, :period => '7_days'
192 192 assert_response :success
193 193 assert_template 'details'
194 194 assert_not_nil assigns(:entries)
195 195 assert_not_nil assigns(:total_hours)
196 196 assert_equal Date.today - 7, assigns(:from)
197 197 assert_equal Date.today, assigns(:to)
198 198 end
199 199
200 200 def test_details_at_issue_level
201 201 get :details, :issue_id => 1
202 202 assert_response :success
203 203 assert_template 'details'
204 204 assert_not_nil assigns(:entries)
205 205 assert_equal 2, assigns(:entries).size
206 206 assert_not_nil assigns(:total_hours)
207 207 assert_equal 154.25, assigns(:total_hours)
208 208 # display all time by default
209 209 assert_equal '2007-03-11'.to_date, assigns(:from)
210 210 assert_equal '2007-04-22'.to_date, assigns(:to)
211 211 end
212 212
213 def test_details_atom_feed
214 get :details, :project_id => 1, :format => 'atom'
215 assert_response :success
216 assert_equal 'application/atom+xml', @response.content_type
217 assert_not_nil assigns(:items)
218 assert assigns(:items).first.is_a?(TimeEntry)
219 end
220
213 221 def test_details_csv_export
214 222 get :details, :project_id => 1, :format => 'csv'
215 223 assert_response :success
216 224 assert_equal 'text/csv', @response.content_type
217 225 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
218 226 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
219 227 end
220 228 end
General Comments 0
You need to be logged in to leave comments. Login now