##// END OF EJS Templates
Merged r14162 (#19464)....
Jean-Philippe Lang -
r13824:94910b1e0924
parent child
Show More
@@ -68,10 +68,15 class TimeEntry < ActiveRecord::Base
68 68 def safe_attributes=(attrs, user=User.current)
69 69 if attrs
70 70 attrs = super(attrs)
71 if issue_id_changed? && attrs[:project_id].blank? && issue && issue.project_id != project_id
71 if issue_id_changed? && issue
72 72 if user.allowed_to?(:log_time, issue.project)
73 if attrs[:project_id].blank? && issue.project_id != project_id
73 74 self.project_id = issue.project_id
74 75 end
76 @invalid_issue_id = nil
77 else
78 @invalid_issue_id = issue_id
79 end
75 80 end
76 81 end
77 82 attrs
@@ -84,7 +89,7 class TimeEntry < ActiveRecord::Base
84 89 def validate_time_entry
85 90 errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
86 91 errors.add :project_id, :invalid if project.nil?
87 errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project)
92 errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
88 93 end
89 94
90 95 def hours=(h)
@@ -162,6 +162,56 class TimelogControllerTest < ActionController::TestCase
162 162 assert_equal 3, t.user_id
163 163 end
164 164
165 def test_create_on_project_with_time_tracking_disabled_should_fail
166 Project.find(1).disable_module! :time_tracking
167
168 @request.session[:user_id] = 2
169 assert_no_difference 'TimeEntry.count' do
170 post :create, :time_entry => {
171 :project_id => '1', :issue_id => '',
172 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
173 }
174 end
175 end
176
177 def test_create_on_project_without_permission_should_fail
178 Role.find(1).remove_permission! :log_time
179
180 @request.session[:user_id] = 2
181 assert_no_difference 'TimeEntry.count' do
182 post :create, :time_entry => {
183 :project_id => '1', :issue_id => '',
184 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
185 }
186 end
187 end
188
189 def test_create_on_issue_in_project_with_time_tracking_disabled_should_fail
190 Project.find(1).disable_module! :time_tracking
191
192 @request.session[:user_id] = 2
193 assert_no_difference 'TimeEntry.count' do
194 post :create, :time_entry => {
195 :project_id => '', :issue_id => '1',
196 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
197 }
198 assert_select_error /Issue is invalid/
199 end
200 end
201
202 def test_create_on_issue_in_project_without_permission_should_fail
203 Role.find(1).remove_permission! :log_time
204
205 @request.session[:user_id] = 2
206 assert_no_difference 'TimeEntry.count' do
207 post :create, :time_entry => {
208 :project_id => '', :issue_id => '1',
209 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
210 }
211 assert_select_error /Issue is invalid/
212 end
213 end
214
165 215 def test_create_and_continue_at_project_level
166 216 @request.session[:user_id] = 2
167 217 assert_difference 'TimeEntry.count' do
General Comments 0
You need to be logged in to leave comments. Login now