]> git.openstreetmap.org Git - rails.git/blob - test/models/diary_comment_test.rb
Exclude `opening_hours` from semicolon splitting in tags helper (#6968)
[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   def setup
7     # Create the default language for diary entries
8     create(:language, :code => "en")
9   end
10
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"
15   end
16
17   test "body must not be too long" do
18     comment = build(:diary_comment, :body => "x" * 65536)
19     assert_predicate comment, :valid?
20
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"
24   end
25
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)
37
38     assert_equal comment.notifiable_subscribers.sort, [commenter1, commenter3].sort
39   end
40 end