belongs_to :user
validates :body, :presence => true, :characters => true
+
+ def body
+ RichText.new("markdown", self[:body])
+ end
end
<%= 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>
--- /dev/null
+FactoryBot.define do
+ factory :issue_comment do
+ sequence(:body) { |n| "This is issue comment #{n}" }
+
+ issue
+ user
+ end
+end
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