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 create(:diary_comment, :diary_entry => diary)
32 assert_equal(1, diary.comments.count)
35 def test_diary_entry_visible_comments
36 diary = create(:diary_entry)
37 create(:diary_comment, :diary_entry => diary)
38 create(:diary_comment, :diary_entry => diary, :visible => false)
39 assert_equal 1, diary.visible_comments.count
40 assert_equal 2, diary.comments.count
45 def diary_entry_valid(attrs, result = true)
46 entry = DiaryEntry.new(attributes_for(:diary_entry))
47 entry.assign_attributes(attrs)
48 assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"