Added a few more tests
authorShrey <shrey14099@iiitd.ac.in>
Fri, 19 Jun 2015 15:32:33 +0000 (21:02 +0530)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 22 Aug 2016 15:17:54 +0000 (16:17 +0100)
app/controllers/issues_controller.rb
app/views/issues/_comments.html.erb
config/locales/en-GB.yml
config/locales/en.yml
test/controllers/issues_controller_test.rb

index bcea64b..5501402 100644 (file)
@@ -139,16 +139,21 @@ class IssuesController < ApplicationController
 
   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
index 2e259a1..52f740b 100644 (file)
@@ -20,7 +20,7 @@
 <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/>
index e62069a..4f0fb9f 100644 (file)
@@ -956,7 +956,10 @@ en-GB:
     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'
index c65f51b..9fc1785 100644 (file)
@@ -927,6 +927,9 @@ en:
       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'
index 87eda15..a6e1d6b 100644 (file)
@@ -199,4 +199,27 @@ class IssuesControllerTest < ActionController::TestCase
     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