From e204e1d178242c450ca0db46724dc9d7e5e11665 Mon Sep 17 00:00:00 2001
From: Harry Wood
Date: Fri, 6 May 2022 12:38:17 +0100
Subject: [PATCH 1/2] Add some basic testing of issue_comment model
A factory and a basic test of validation for the issue_comment model, similar to what we have for diary_comment.
---
test/factories/issue_comment.rb | 8 ++++++++
test/models/issue_comment_test.rb | 8 +++++---
2 files changed, 13 insertions(+), 3 deletions(-)
create mode 100644 test/factories/issue_comment.rb
diff --git a/test/factories/issue_comment.rb b/test/factories/issue_comment.rb
new file mode 100644
index 000000000..52316954d
--- /dev/null
+++ b/test/factories/issue_comment.rb
@@ -0,0 +1,8 @@
+FactoryBot.define do
+ factory :issue_comment do
+ sequence(:body) { |n| "This is issue comment #{n}" }
+
+ issue
+ user
+ end
+end
diff --git a/test/models/issue_comment_test.rb b/test/models/issue_comment_test.rb
index 53ba35889..27fa9d66d 100644
--- a/test/models/issue_comment_test.rb
+++ b/test/models/issue_comment_test.rb
@@ -1,7 +1,9 @@
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
end
From 3ca8b63643b9cfa6ef964673aa4fff2cbeee78a3 Mon Sep 17 00:00:00 2001
From: Harry Wood
Date: Fri, 6 May 2022 12:41:04 +0100
Subject: [PATCH 2/2] Put issue comments through kramdown formatter
On issue comments (which only admins can create or see), put the `body` text through kramdown formatting.
---
app/models/issue_comment.rb | 4 ++++
app/views/issues/_comments.html.erb | 2 +-
test/models/issue_comment_test.rb | 5 +++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/app/models/issue_comment.rb b/app/models/issue_comment.rb
index 07647d679..8d150a02f 100644
--- a/app/models/issue_comment.rb
+++ b/app/models/issue_comment.rb
@@ -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
diff --git a/app/views/issues/_comments.html.erb b/app/views/issues/_comments.html.erb
index e55bf4257..390977b65 100644
--- a/app/views/issues/_comments.html.erb
+++ b/app/views/issues/_comments.html.erb
@@ -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) %>
- <%= comment.body %>
+ <%= comment.body.to_html %>
diff --git a/test/models/issue_comment_test.rb b/test/models/issue_comment_test.rb
index 27fa9d66d..7a1191ead 100644
--- a/test/models/issue_comment_test.rb
+++ b/test/models/issue_comment_test.rb
@@ -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