3 class DiaryEntryTest < ActiveSupport::TestCase
7 # Create the default language for diary entries
8 create(:language, :code => "en")
11 def test_diary_entry_validations
13 diary_entry_valid({ :title => "" }, false)
14 diary_entry_valid(:title => "a" * 255)
15 diary_entry_valid({ :title => "a" * 256 }, false)
16 diary_entry_valid({ :body => "" }, false)
17 diary_entry_valid(:latitude => 90)
18 diary_entry_valid({ :latitude => 90.00001 }, false)
19 diary_entry_valid(:latitude => -90)
20 diary_entry_valid({ :latitude => -90.00001 }, false)
21 diary_entry_valid(:longitude => 180)
22 diary_entry_valid({ :longitude => 180.00001 }, false)
23 diary_entry_valid(:longitude => -180)
24 diary_entry_valid({ :longitude => -180.00001 }, false)
27 def test_diary_entry_visible
28 visible = create(:diary_entry)
29 hidden = create(:diary_entry, :visible => false)
30 assert_includes DiaryEntry.visible, visible
31 assert_raise ActiveRecord::RecordNotFound do
32 DiaryEntry.visible.find(hidden.id)
36 def test_diary_entry_comments
37 diary = create(:diary_entry)
38 assert_equal(0, diary.comments.count)
39 create(:diary_comment, :diary_entry => diary)
40 assert_equal(1, diary.comments.count)
43 def test_diary_entry_visible_comments
44 diary = create(:diary_entry)
45 create(:diary_comment, :diary_entry => diary)
46 create(:diary_comment, :diary_entry => diary, :visible => false)
47 assert_equal 1, diary.visible_comments.count
48 assert_equal 2, diary.comments.count
53 def diary_entry_valid(attrs, result = true)
54 entry = build(:diary_entry, attrs)
55 assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"