]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/3543'
authorTom Hughes <tom@compton.nu>
Sat, 7 May 2022 07:19:19 +0000 (08:19 +0100)
committerTom Hughes <tom@compton.nu>
Sat, 7 May 2022 07:19:19 +0000 (08:19 +0100)
app/models/issue_comment.rb
app/views/issues/_comments.html.erb
test/factories/issue_comment.rb [new file with mode: 0644]
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>
diff --git a/test/factories/issue_comment.rb b/test/factories/issue_comment.rb
new file mode 100644 (file)
index 0000000..5231695
--- /dev/null
@@ -0,0 +1,8 @@
+FactoryBot.define do
+  factory :issue_comment do
+    sequence(:body) { |n| "This is issue comment #{n}" }
+
+    issue
+    user
+  end
+end
index 53ba358895999bb54b3eff1e71a27d6c22a143f9..7a1191ead0052653ebf49bd9da8310dea0e36eb6 100644 (file)
@@ -1,7 +1,14 @@
 require "test_helper"
 
 class IssueCommentTest < ActiveSupport::TestCase
-  # test "the truth" do
-  #   assert true
-  # end
+  test "body must be present" do
+    comment = build(:issue_comment, :body => "")
+    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