summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-03-13 16:38:01 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-03-13 16:38:01 +0000
commit7927bc2d892b018b00b1fc5be507e11053db99dd (patch)
tree33b07fe4eaef806e444db3b2aa1ae62c9a8dbca5
parent8d641203d4f5a5ef0143ee45b5a671857a9c9f00 (diff)
downloadredmine-7927bc2d892b018b00b1fc5be507e11053db99dd.tar.gz
redmine-7927bc2d892b018b00b1fc5be507e11053db99dd.zip
Check for a valid time entry if comments have been entered when updating an issue (#7581).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5110 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/issue.rb2
-rw-r--r--test/functional/issues_controller_test.rb25
2 files changed, 23 insertions, 4 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index de31aa636..92ab64a8c 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -536,7 +536,7 @@ class Issue < ActiveRecord::Base
# Returns false if save fails
def save_issue_with_child_records(params, existing_time_entry=nil)
Issue.transaction do
- if params[:time_entry] && params[:time_entry][:hours].present? && User.current.allowed_to?(:log_time, project)
+ if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, project)
@time_entry = existing_time_entry || TimeEntry.new
@time_entry.project = project
@time_entry.issue = self
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index b21b28e66..36421aa89 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -1002,7 +1002,7 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 1, ActionMailer::Base.deliveries.size
end
- def test_put_update_with_invalid_spent_time
+ def test_put_update_with_invalid_spent_time_hours_only
@request.session[:user_id] = 2
notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
@@ -1015,11 +1015,30 @@ class IssuesControllerTest < ActionController::TestCase
assert_response :success
assert_template 'edit'
- assert_tag :textarea, :attributes => { :name => 'notes' },
- :content => notes
+ assert_error_tag :descendant => {:content => /Activity can't be blank/}
+ assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
end
+ def test_put_update_with_invalid_spent_time_comments_only
+ @request.session[:user_id] = 2
+ notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
+
+ assert_no_difference('Journal.count') do
+ put :update,
+ :id => 1,
+ :notes => notes,
+ :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
+ end
+ assert_response :success
+ assert_template 'edit'
+
+ assert_error_tag :descendant => {:content => /Activity can't be blank/}
+ assert_error_tag :descendant => {:content => /Hours can't be blank/}
+ assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
+ assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
+ end
+
def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
issue = Issue.find(2)
@request.session[:user_id] = 2