##// END OF EJS Templates
Merged r9709 from trunk....
Jean-Philippe Lang -
r9538:7f51bab0fcb0
parent child
Show More
@@ -1,52 +1,52
1 <h3><%=l(:label_spent_time)%> (<%= l(:label_last_n_days, 7) %>)</h3>
1 <h3><%=l(:label_spent_time)%> (<%= l(:label_last_n_days, 7) %>)</h3>
2 <%
2 <%
3 entries = TimeEntry.find(:all,
3 entries = TimeEntry.find(:all,
4 :conditions => ["#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", @user.id, Date.today - 6, Date.today],
4 :conditions => ["#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", @user.id, Date.today - 6, Date.today],
5 :include => [:activity, :project, {:issue => [:tracker, :status]}],
5 :include => [:activity, :project, {:issue => [:tracker, :status]}],
6 :order => "#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC")
6 :order => "#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC")
7 entries_by_day = entries.group_by(&:spent_on)
7 entries_by_day = entries.group_by(&:spent_on)
8 %>
8 %>
9
9
10 <div class="total-hours">
10 <div class="total-hours">
11 <p><%= l(:label_total) %>: <%= html_hours("%.2f" % entries.sum(&:hours).to_f) %></p>
11 <p><%= l(:label_total) %>: <%= html_hours("%.2f" % entries.sum(&:hours).to_f) %></p>
12 </div>
12 </div>
13
13
14 <% if entries.any? %>
14 <% if entries.any? %>
15 <table class="list time-entries">
15 <table class="list time-entries">
16 <thead><tr>
16 <thead><tr>
17 <th><%= l(:label_activity) %></th>
17 <th><%= l(:label_activity) %></th>
18 <th><%= l(:label_project) %></th>
18 <th><%= l(:label_project) %></th>
19 <th><%= l(:field_comments) %></th>
19 <th><%= l(:field_comments) %></th>
20 <th><%= l(:field_hours) %></th>
20 <th><%= l(:field_hours) %></th>
21 <th></th>
21 <th></th>
22 </tr></thead>
22 </tr></thead>
23 <tbody>
23 <tbody>
24 <% entries_by_day.keys.sort.reverse.each do |day| %>
24 <% entries_by_day.keys.sort.reverse.each do |day| %>
25 <tr class="odd">
25 <tr class="odd">
26 <td><strong><%= day == Date.today ? l(:label_today).titleize : format_date(day) %></strong></td>
26 <td><strong><%= day == Date.today ? l(:label_today).titleize : format_date(day) %></strong></td>
27 <td colspan="2"></td>
27 <td colspan="2"></td>
28 <td class="hours"><em><%= html_hours("%.2f" % entries_by_day[day].sum(&:hours).to_f) %></em></td>
28 <td class="hours"><em><%= html_hours("%.2f" % entries_by_day[day].sum(&:hours).to_f) %></em></td>
29 <td></td>
29 <td></td>
30 </tr>
30 </tr>
31 <% entries_by_day[day].each do |entry| -%>
31 <% entries_by_day[day].each do |entry| -%>
32 <tr class="time-entry" style="border-bottom: 1px solid #f5f5f5;">
32 <tr class="time-entry" style="border-bottom: 1px solid #f5f5f5;">
33 <td class="activity"><%=h entry.activity %></td>
33 <td class="activity"><%=h entry.activity %></td>
34 <td class="subject"><%=h entry.project %> <%= ' - ' + link_to_issue(entry.issue, :truncate => 50) if entry.issue %></td>
34 <td class="subject"><%=h entry.project %> <%= h(' - ') + link_to_issue(entry.issue, :truncate => 50) if entry.issue %></td>
35 <td class="comments"><%=h entry.comments %></td>
35 <td class="comments"><%=h entry.comments %></td>
36 <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
36 <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
37 <td align="center">
37 <td align="center">
38 <% if entry.editable_by?(@user) -%>
38 <% if entry.editable_by?(@user) -%>
39 <%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => entry},
39 <%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => entry},
40 :title => l(:button_edit) %>
40 :title => l(:button_edit) %>
41 <%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => entry},
41 <%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => entry},
42 :confirm => l(:text_are_you_sure),
42 :confirm => l(:text_are_you_sure),
43 :method => :delete,
43 :method => :delete,
44 :title => l(:button_delete) %>
44 :title => l(:button_delete) %>
45 <% end -%>
45 <% end -%>
46 </td>
46 </td>
47 </tr>
47 </tr>
48 <% end -%>
48 <% end -%>
49 <% end -%>
49 <% end -%>
50 </tbody>
50 </tbody>
51 </table>
51 </table>
52 <% end %>
52 <% end %>
@@ -1,224 +1,239
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'my_controller'
19 require 'my_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class MyController; def rescue_action(e) raise e end; end
22 class MyController; def rescue_action(e) raise e end; end
23
23
24 class MyControllerTest < ActionController::TestCase
24 class MyControllerTest < ActionController::TestCase
25 fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
25 fixtures :users, :user_preferences, :roles, :projects, :members, :member_roles,
26 :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
26
27
27 def setup
28 def setup
28 @controller = MyController.new
29 @controller = MyController.new
29 @request = ActionController::TestRequest.new
30 @request = ActionController::TestRequest.new
30 @request.session[:user_id] = 2
31 @request.session[:user_id] = 2
31 @response = ActionController::TestResponse.new
32 @response = ActionController::TestResponse.new
32 end
33 end
33
34
34 def test_index
35 def test_index
35 get :index
36 get :index
36 assert_response :success
37 assert_response :success
37 assert_template 'page'
38 assert_template 'page'
38 end
39 end
39
40
40 def test_page
41 def test_page
41 get :page
42 get :page
42 assert_response :success
43 assert_response :success
43 assert_template 'page'
44 assert_template 'page'
44 end
45 end
45
46
47 def test_page_with_timelog_block
48 preferences = User.find(2).pref
49 preferences[:my_page_layout] = {'top' => ['timelog']}
50 preferences.save!
51 TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :issue_id => 1, :hours => 2.5, :activity_id => 10)
52
53 get :page
54 assert_response :success
55 assert_select 'tr.time-entry' do
56 assert_select 'td.subject a[href=/issues/1]'
57 assert_select 'td.hours', :text => '2.50'
58 end
59 end
60
46 def test_my_account_should_show_editable_custom_fields
61 def test_my_account_should_show_editable_custom_fields
47 get :account
62 get :account
48 assert_response :success
63 assert_response :success
49 assert_template 'account'
64 assert_template 'account'
50 assert_equal User.find(2), assigns(:user)
65 assert_equal User.find(2), assigns(:user)
51
66
52 assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
67 assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
53 end
68 end
54
69
55 def test_my_account_should_not_show_non_editable_custom_fields
70 def test_my_account_should_not_show_non_editable_custom_fields
56 UserCustomField.find(4).update_attribute :editable, false
71 UserCustomField.find(4).update_attribute :editable, false
57
72
58 get :account
73 get :account
59 assert_response :success
74 assert_response :success
60 assert_template 'account'
75 assert_template 'account'
61 assert_equal User.find(2), assigns(:user)
76 assert_equal User.find(2), assigns(:user)
62
77
63 assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
78 assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
64 end
79 end
65
80
66 def test_update_account
81 def test_update_account
67 post :account,
82 post :account,
68 :user => {
83 :user => {
69 :firstname => "Joe",
84 :firstname => "Joe",
70 :login => "root",
85 :login => "root",
71 :admin => 1,
86 :admin => 1,
72 :group_ids => ['10'],
87 :group_ids => ['10'],
73 :custom_field_values => {"4" => "0100562500"}
88 :custom_field_values => {"4" => "0100562500"}
74 }
89 }
75
90
76 assert_redirected_to '/my/account'
91 assert_redirected_to '/my/account'
77 user = User.find(2)
92 user = User.find(2)
78 assert_equal user, assigns(:user)
93 assert_equal user, assigns(:user)
79 assert_equal "Joe", user.firstname
94 assert_equal "Joe", user.firstname
80 assert_equal "jsmith", user.login
95 assert_equal "jsmith", user.login
81 assert_equal "0100562500", user.custom_value_for(4).value
96 assert_equal "0100562500", user.custom_value_for(4).value
82 # ignored
97 # ignored
83 assert !user.admin?
98 assert !user.admin?
84 assert user.groups.empty?
99 assert user.groups.empty?
85 end
100 end
86
101
87 def test_my_account_should_show_destroy_link
102 def test_my_account_should_show_destroy_link
88 get :account
103 get :account
89 assert_select 'a[href=/my/account/destroy]'
104 assert_select 'a[href=/my/account/destroy]'
90 end
105 end
91
106
92 def test_get_destroy_should_display_the_destroy_confirmation
107 def test_get_destroy_should_display_the_destroy_confirmation
93 get :destroy
108 get :destroy
94 assert_response :success
109 assert_response :success
95 assert_template 'destroy'
110 assert_template 'destroy'
96 assert_select 'form[action=/my/account/destroy]' do
111 assert_select 'form[action=/my/account/destroy]' do
97 assert_select 'input[name=confirm]'
112 assert_select 'input[name=confirm]'
98 end
113 end
99 end
114 end
100
115
101 def test_post_destroy_without_confirmation_should_not_destroy_account
116 def test_post_destroy_without_confirmation_should_not_destroy_account
102 assert_no_difference 'User.count' do
117 assert_no_difference 'User.count' do
103 post :destroy
118 post :destroy
104 end
119 end
105 assert_response :success
120 assert_response :success
106 assert_template 'destroy'
121 assert_template 'destroy'
107 end
122 end
108
123
109 def test_post_destroy_without_confirmation_should_destroy_account
124 def test_post_destroy_without_confirmation_should_destroy_account
110 assert_difference 'User.count', -1 do
125 assert_difference 'User.count', -1 do
111 post :destroy, :confirm => '1'
126 post :destroy, :confirm => '1'
112 end
127 end
113 assert_redirected_to '/'
128 assert_redirected_to '/'
114 assert_match /deleted/i, flash[:notice]
129 assert_match /deleted/i, flash[:notice]
115 end
130 end
116
131
117 def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account
132 def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account
118 User.any_instance.stubs(:own_account_deletable?).returns(false)
133 User.any_instance.stubs(:own_account_deletable?).returns(false)
119
134
120 assert_no_difference 'User.count' do
135 assert_no_difference 'User.count' do
121 post :destroy, :confirm => '1'
136 post :destroy, :confirm => '1'
122 end
137 end
123 assert_redirected_to '/my/account'
138 assert_redirected_to '/my/account'
124 end
139 end
125
140
126 def test_change_password
141 def test_change_password
127 get :password
142 get :password
128 assert_response :success
143 assert_response :success
129 assert_template 'password'
144 assert_template 'password'
130
145
131 # non matching password confirmation
146 # non matching password confirmation
132 post :password, :password => 'jsmith',
147 post :password, :password => 'jsmith',
133 :new_password => 'hello',
148 :new_password => 'hello',
134 :new_password_confirmation => 'hello2'
149 :new_password_confirmation => 'hello2'
135 assert_response :success
150 assert_response :success
136 assert_template 'password'
151 assert_template 'password'
137 assert_error_tag :content => /Password doesn't match confirmation/
152 assert_error_tag :content => /Password doesn't match confirmation/
138
153
139 # wrong password
154 # wrong password
140 post :password, :password => 'wrongpassword',
155 post :password, :password => 'wrongpassword',
141 :new_password => 'hello',
156 :new_password => 'hello',
142 :new_password_confirmation => 'hello'
157 :new_password_confirmation => 'hello'
143 assert_response :success
158 assert_response :success
144 assert_template 'password'
159 assert_template 'password'
145 assert_equal 'Wrong password', flash[:error]
160 assert_equal 'Wrong password', flash[:error]
146
161
147 # good password
162 # good password
148 post :password, :password => 'jsmith',
163 post :password, :password => 'jsmith',
149 :new_password => 'hello',
164 :new_password => 'hello',
150 :new_password_confirmation => 'hello'
165 :new_password_confirmation => 'hello'
151 assert_redirected_to '/my/account'
166 assert_redirected_to '/my/account'
152 assert User.try_to_login('jsmith', 'hello')
167 assert User.try_to_login('jsmith', 'hello')
153 end
168 end
154
169
155 def test_change_password_should_redirect_if_user_cannot_change_its_password
170 def test_change_password_should_redirect_if_user_cannot_change_its_password
156 User.find(2).update_attribute(:auth_source_id, 1)
171 User.find(2).update_attribute(:auth_source_id, 1)
157
172
158 get :password
173 get :password
159 assert_not_nil flash[:error]
174 assert_not_nil flash[:error]
160 assert_redirected_to '/my/account'
175 assert_redirected_to '/my/account'
161 end
176 end
162
177
163 def test_page_layout
178 def test_page_layout
164 get :page_layout
179 get :page_layout
165 assert_response :success
180 assert_response :success
166 assert_template 'page_layout'
181 assert_template 'page_layout'
167 end
182 end
168
183
169 def test_add_block
184 def test_add_block
170 xhr :post, :add_block, :block => 'issuesreportedbyme'
185 xhr :post, :add_block, :block => 'issuesreportedbyme'
171 assert_response :success
186 assert_response :success
172 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
187 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
173 end
188 end
174
189
175 def test_remove_block
190 def test_remove_block
176 xhr :post, :remove_block, :block => 'issuesassignedtome'
191 xhr :post, :remove_block, :block => 'issuesassignedtome'
177 assert_response :success
192 assert_response :success
178 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
193 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
179 end
194 end
180
195
181 def test_order_blocks
196 def test_order_blocks
182 xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews']
197 xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews']
183 assert_response :success
198 assert_response :success
184 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
199 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
185 end
200 end
186
201
187 def test_reset_rss_key_with_existing_key
202 def test_reset_rss_key_with_existing_key
188 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
203 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
189 post :reset_rss_key
204 post :reset_rss_key
190
205
191 assert_not_equal @previous_token_value, User.find(2).rss_key
206 assert_not_equal @previous_token_value, User.find(2).rss_key
192 assert User.find(2).rss_token
207 assert User.find(2).rss_token
193 assert_match /reset/, flash[:notice]
208 assert_match /reset/, flash[:notice]
194 assert_redirected_to '/my/account'
209 assert_redirected_to '/my/account'
195 end
210 end
196
211
197 def test_reset_rss_key_without_existing_key
212 def test_reset_rss_key_without_existing_key
198 assert_nil User.find(2).rss_token
213 assert_nil User.find(2).rss_token
199 post :reset_rss_key
214 post :reset_rss_key
200
215
201 assert User.find(2).rss_token
216 assert User.find(2).rss_token
202 assert_match /reset/, flash[:notice]
217 assert_match /reset/, flash[:notice]
203 assert_redirected_to '/my/account'
218 assert_redirected_to '/my/account'
204 end
219 end
205
220
206 def test_reset_api_key_with_existing_key
221 def test_reset_api_key_with_existing_key
207 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
222 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
208 post :reset_api_key
223 post :reset_api_key
209
224
210 assert_not_equal @previous_token_value, User.find(2).api_key
225 assert_not_equal @previous_token_value, User.find(2).api_key
211 assert User.find(2).api_token
226 assert User.find(2).api_token
212 assert_match /reset/, flash[:notice]
227 assert_match /reset/, flash[:notice]
213 assert_redirected_to '/my/account'
228 assert_redirected_to '/my/account'
214 end
229 end
215
230
216 def test_reset_api_key_without_existing_key
231 def test_reset_api_key_without_existing_key
217 assert_nil User.find(2).api_token
232 assert_nil User.find(2).api_token
218 post :reset_api_key
233 post :reset_api_key
219
234
220 assert User.find(2).api_token
235 assert User.find(2).api_token
221 assert_match /reset/, flash[:notice]
236 assert_match /reset/, flash[:notice]
222 assert_redirected_to '/my/account'
237 assert_redirected_to '/my/account'
223 end
238 end
224 end
239 end
General Comments 0
You need to be logged in to leave comments. Login now