def comment
@issue = Issue.find(params[:id])
- @issue_comment = @issue.comments.build(issue_comment_params)
- @issue_comment.commenter_user_id = @user.id
- if params[:reassign]
- reassign_issue
- @issue_comment.reassign = true
- end
- @issue_comment.save!
- @issue.updated_by = @user.id
- @issue.save!
- redirect_to @issue
+ if issue_comment_params.blank?
+ notice = t('issues.comment.provide_details')
+ else
+ @issue_comment = @issue.comments.build(issue_comment_params)
+ @issue_comment.commenter_user_id = @user.id
+ if params[:reassign]
+ reassign_issue
+ @issue_comment.reassign = true
+ end
+ @issue_comment.save!
+ @issue.updated_by = @user.id
+ @issue.save!
+ notice = t('issues.comment.comment_created')
+ end
+ redirect_to @issue, notice: notice
end
# Status Transistions
<br/>
<div class="comment">
<%= form_for :issue_comment, :url => { :action => 'comment', :id => @issue.id, :user_id => @user.id } do |f| %>
- <%= richtext_area :issue_comment, :body, :cols => 10, :rows => 8 %>
+ <%= richtext_area :issue_comment, :body, :cols => 10, :rows => 8, :required => true %>
<%= label_tag t('issues.show.comments.reassign_param') %> <%= check_box_tag :reassign, true %>
<br/>
<br/>
show:
comments:
reassign: The Issue was reassigned
- reassign_param: Reassign Issue?
+ reassign_param: Reassign Issue?
+ comment:
+ provide_details: Please provide the required details
+ comment_created: Your comment was successfully created
resolved: Issue status has been set to 'Resolved'
ignored: Issue status has been set to 'Ignored'
reopened: Issue status has been set to 'Open'
comments:
reassign: The Issue was reassigned
reassign_param: Reassign Issue?
+ comment:
+ provide_details: Please provide the required details
+ comment_created: Your comment was successfully created
resolved: Issue status has been set to 'Resolved'
ignored: Issue status has been set to 'Ignored'
reopened: Issue status has been set to 'Open'
assert_response :success
end
+ def test_comment_by_normal_user
+ # Create Issue
+ test_new_issue_after_login
+ assert_equal Issue.count,1
+
+ get :comment, id: 1
+ assert_response :redirect
+ assert_redirected_to root_path
+ end
+
+ def test_comment
+ # Create Issue
+ test_new_issue_after_login
+ assert_equal Issue.count,1
+ @issue = Issue.all.first
+
+ # Login as administrator
+ session[:user] = users(:administrator_user).id
+
+ get :comment, id: @issue.id, :issue_comment => { body: "test comment" }
+ assert_response :redirect
+ assert_redirected_to @issue
+ end
end