]> git.openstreetmap.org Git - rails.git/blob - test/models/diary_comment_test.rb
Merge pull request #7052 from openstreetmap/translatewiki
[rails.git] / test / models / diary_comment_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
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"
10   end
11
12   test "body must not be too long" do
13     comment = build(:diary_comment, :body => "x" * 65536)
14     assert_predicate comment, :valid?
15
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"
19   end
20
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)
32
33     assert_equal comment.notifiable_subscribers.sort, [commenter1, commenter3].sort
34   end
35 end