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