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