]> git.openstreetmap.org Git - rails.git/commitdiff
Put issue comments through kramdown formatter
authorHarry Wood <github@harrywood.co.uk>
Fri, 6 May 2022 11:41:04 +0000 (12:41 +0100)
committerHarry Wood <github@harrywood.co.uk>
Fri, 6 May 2022 12:36:59 +0000 (13:36 +0100)
On issue comments (which only admins can create or see), put the `body` text through kramdown formatting.

app/models/issue_comment.rb
app/views/issues/_comments.html.erb
test/models/issue_comment_test.rb

index 07647d67946f221564dc7667065ee8f737c99aa0..8d150a02f8b88512fdf47070c162dfaadb2dd4e7 100644 (file)
@@ -25,4 +25,8 @@ class IssueComment < ApplicationRecord
   belongs_to :user
 
   validates :body, :presence => true, :characters => true
+
+  def body
+    RichText.new("markdown", self[:body])
+  end
 end
index e55bf42578fb5200ccf94040f02113b32fd7599c..390977b655601e54b3710ee93b9b4f7025517014 100644 (file)
@@ -9,7 +9,7 @@
           <%= t ".comment_from_html", :user_link => link_to(comment.user.display_name, user_path(comment.user)),
                                       :comment_created_at => l(comment.created_at.to_datetime, :format => :friendly) %>
         </p>
-        <p><%= comment.body %></p>
+        <p><%= comment.body.to_html %></p>
       </div>
     </div>
     <hr>
index 27fa9d66d878bbfeeee918ee6a3a6edd9c14196d..7a1191ead0052653ebf49bd9da8310dea0e36eb6 100644 (file)
@@ -6,4 +6,9 @@ class IssueCommentTest < ActiveSupport::TestCase
     assert_not comment.valid?
     assert_not_nil comment.errors[:body]
   end
+
+  test "body" do
+    comment = create(:issue_comment)
+    assert_instance_of(RichText::Markdown, comment.body)
+  end
 end