1 # frozen_string_literal: true
5 class DiaryCommentTest < ActiveSupport::TestCase
6 test "body must be present" do
7 comment = build(:diary_comment, :body => "")
8 assert_not comment.valid?
9 assert_not_nil comment.errors[:body], "no validation error for missing body"
12 test "body must not be too long" do
13 comment = build(:diary_comment, :body => "x" * 65536)
14 assert_predicate comment, :valid?
16 comment = build(:diary_comment, :body => "x" * 65537)
17 assert_not_predicate comment, :valid?
18 assert_not_nil comment.errors[:body], "no validation error for body too long"
21 test "the correct subscribers are notified" do
22 commenter1 = create(:user)
23 commenter2 = create(:user, :suspended)
24 commenter3 = create(:user)
25 commenter4 = create(:user)
26 diary_entry = create(:diary_entry)
27 create(:diary_entry_subscription, :diary_entry => diary_entry, :user => commenter1)
28 create(:diary_entry_subscription, :diary_entry => diary_entry, :user => commenter2)
29 create(:diary_entry_subscription, :diary_entry => diary_entry, :user => commenter3)
30 create(:diary_entry_subscription, :diary_entry => diary_entry, :user => commenter4)
31 comment = create(:diary_comment, :diary_entry => diary_entry, :user => commenter4)
33 assert_equal comment.notifiable_subscribers.sort, [commenter1, commenter3].sort