From: Tom Hughes Date: Sat, 7 May 2022 07:19:19 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/3543' X-Git-Tag: live~1744 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/407287512f90e6e55fbb71e8d8d8d2d1d96d2999?hp=ef12e7d4722e87aa01e70a4a4f4fa52acc031306 Merge remote-tracking branch 'upstream/pull/3543' --- 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/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..7a1191ead 100644 --- a/test/models/issue_comment_test.rb +++ b/test/models/issue_comment_test.rb @@ -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