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