]> git.openstreetmap.org Git - rails.git/blob - test/unit/diary_entry_test.rb
Merge branch 'master' into openstreetbugs
[rails.git] / test / unit / diary_entry_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class DiaryEntryTest < ActiveSupport::TestCase
4   api_fixtures
5   fixtures :diary_entries, :diary_comments, :languages
6   
7   def test_diary_entry_count
8     assert_equal 3, DiaryEntry.count
9   end
10   
11   def test_diary_entry_validations
12     diary_entry_valid({})
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)
25   end
26
27   def test_diary_entry_visible
28     assert_equal 2, DiaryEntry.visible.count
29     assert_raise ActiveRecord::RecordNotFound do
30       DiaryEntry.visible.find(diary_entries(:deleted_entry).id)
31     end
32   end
33   
34   def test_diary_entry_comments
35     assert_equal 0, diary_entries(:normal_user_entry_1).comments.count
36     assert_equal 3, diary_entries(:normal_user_geo_entry).comments.count
37   end
38   
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
42   end
43
44 private
45
46   def diary_entry_valid(attrs, result = true)
47     entry = DiaryEntry.new(diary_entries(:normal_user_entry_1).attributes, :without_protection => true)
48     entry.assign_attributes(attrs, :without_protection => true)
49     assert_equal result, entry.valid?, "Expected #{attrs.inspect} to be #{result}"
50   end  
51 end