3 class DiaryEntryTest < ActiveSupport::TestCase
4 def test_diary_entry_validations
6 diary_entry_valid({ :title => "" }, false)
7 diary_entry_valid(:title => "a" * 255)
8 diary_entry_valid({ :title => "a" * 256 }, false)
9 diary_entry_valid({ :body => "" }, false)
10 diary_entry_valid(:latitude => 90)
11 diary_entry_valid({ :latitude => 90.00001 }, false)
12 diary_entry_valid(:latitude => -90)
13 diary_entry_valid({ :latitude => -90.00001 }, false)
14 diary_entry_valid(:longitude => 180)
15 diary_entry_valid({ :longitude => 180.00001 }, false)
16 diary_entry_valid(:longitude => -180)
17 diary_entry_valid({ :longitude => -180.00001 }, false)
20 def test_diary_entry_visible
21 visible = create(:diary_entry)
22 hidden = create(:diary_entry, :visible => false)
23 assert_includes DiaryEntry.visible, visible
24 assert_raise ActiveRecord::RecordNotFound do
25 DiaryEntry.visible.find(hidden.id)
29 def test_diary_entry_comments
30 diary = create(:diary_entry)
31 assert_equal(0, diary.comments.count)
32 create(:diary_comment, :diary_entry => diary)
33 assert_equal(1, diary.comments.count)
36 def test_diary_entry_visible_comments
37 diary = create(:diary_entry)
38 create(:diary_comment, :diary_entry => diary)
39 create(:diary_comment, :diary_entry => diary, :visible => false)
40 assert_equal 1, diary.visible_comments.count
41 assert_equal 2, diary.comments.count
46 def diary_entry_valid(attrs, result = true)
47 entry = build(:diary_entry, attrs)
48 assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"