]> git.openstreetmap.org Git - rails.git/commitdiff
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 bcea64be33de10c1f418d18571cd9ed9ee01bc37..550140232876e2771a1fb6214a070fd934b9606f 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 2e259a1698049dc4754f2a73a85393c4a2fc8165..52f740b0967191576a4aec34e5960d09f0d6f29e 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 e62069a5e6bc59b89b709fce07e58113179f30c9..4f0fb9f03feb2fd363e0f93f6db261c58cdef66f 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 c65f51bc6a71e7ee6e1b7a3bc90372c7ec6129cc..9fc1785b54a112d9fdcaaea9d093a41c76700b32 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 87eda15069df7c9c9340b10ef1d42d62ab3be7de..a6e1d6b3f0ded2f11ef34a917d6352f2372cf8c3 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