3 class DiaryEntryTest < ActiveSupport::TestCase
5 fixtures :diary_entries, :diary_comments, :languages
7 def test_diary_entry_count
8 assert_equal 5, DiaryEntry.count
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 assert_equal 4, DiaryEntry.visible.count
29 assert_raise ActiveRecord::RecordNotFound do
30 DiaryEntry.visible.find(diary_entries(:deleted_entry).id)
34 def test_diary_entry_comments
35 assert_equal 0, diary_entries(:normal_user_entry_1).comments.count
36 assert_equal 4, diary_entries(:normal_user_geo_entry).comments.count
39 def test_diary_entry_visible_comments
40 assert_equal 0, diary_entries(:normal_user_entry_1).visible_comments.count
41 assert_equal 1, diary_entries(:normal_user_geo_entry).visible_comments.count
46 def diary_entry_valid(attrs, result = true)
47 entry = DiaryEntry.new(diary_entries(:normal_user_entry_1).attributes)
48 entry.assign_attributes(attrs)
49 assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"