3 class DiaryEntryTest < ActiveSupport::TestCase
5 # Create the default language for diary entries
6 create(:language, :code => "en")
9 def test_diary_entry_validations
11 diary_entry_valid({ :title => "" }, :valid => false)
12 diary_entry_valid({ :title => "a" * 255 })
13 diary_entry_valid({ :title => "a" * 256 }, :valid => false)
14 diary_entry_valid({ :body => "" }, :valid => false)
15 diary_entry_valid({ :latitude => 90 })
16 diary_entry_valid({ :latitude => 90.00001 }, :valid => false)
17 diary_entry_valid({ :latitude => -90 })
18 diary_entry_valid({ :latitude => -90.00001 }, :valid => false)
19 diary_entry_valid({ :longitude => 180 })
20 diary_entry_valid({ :longitude => 180.00001 }, :valid => false)
21 diary_entry_valid({ :longitude => -180 })
22 diary_entry_valid({ :longitude => -180.00001 }, :valid => false)
25 def test_diary_entry_visible
26 visible = create(:diary_entry)
27 hidden = create(:diary_entry, :visible => false)
28 assert_includes DiaryEntry.visible, visible
29 assert_raise ActiveRecord::RecordNotFound do
30 DiaryEntry.visible.find(hidden.id)
34 def test_diary_entry_comments
35 diary = create(:diary_entry)
36 assert_equal(0, diary.comments.count)
37 create(:diary_comment, :diary_entry => diary)
38 assert_equal(1, diary.comments.count)
41 def test_diary_entry_visible_comments
42 diary = create(:diary_entry)
43 create(:diary_comment, :diary_entry => diary)
44 create(:diary_comment, :diary_entry => diary, :visible => false)
45 assert_equal 1, diary.visible_comments.count
46 assert_equal 2, diary.comments.count
51 def diary_entry_valid(attrs, valid: true)
52 entry = build(:diary_entry, attrs)
53 assert_equal valid, entry.valid?, "Expected #{attrs.inspect} to be #{valid}"