]> git.openstreetmap.org Git - rails.git/blob - test/models/note_test.rb
Merge branch 'wheres_this' of https://github.com/pnorman/openstreetmap-website into...
[rails.git] / test / models / note_test.rb
1 require "test_helper"
2
3 class NoteTest < ActiveSupport::TestCase
4   def test_status_valid
5     ok = %w[open closed hidden]
6     bad = %w[expropriated fubared]
7
8     ok.each do |status|
9       note = create(:note)
10       note.status = status
11       assert note.valid?, "#{status} is invalid, when it should be"
12     end
13
14     bad.each do |status|
15       note = create(:note)
16       note.status = status
17       assert !note.valid?, "#{status} is valid when it shouldn't be"
18     end
19   end
20
21   def test_close
22     note = create(:note)
23     assert_equal "open", note.status
24     assert_nil note.closed_at
25     note.close
26     assert_equal "closed", note.status
27     assert_not_nil note.closed_at
28   end
29
30   def test_reopen
31     note = create(:note, :status => "closed", :closed_at => Time.now)
32     assert_equal "closed", note.status
33     assert_not_nil note.closed_at
34     note.reopen
35     assert_equal "open", note.status
36     assert_nil note.closed_at
37   end
38
39   def test_visible?
40     assert_equal true, create(:note, :status => "open").visible?
41     assert_equal true, create(:note, :status => "closed").visible?
42     assert_equal false, create(:note, :status => "hidden").visible?
43   end
44
45   def test_closed?
46     assert_equal true, create(:note, :status => "closed", :closed_at => Time.now).closed?
47     assert_equal false, create(:note, :status => "open", :closed_at => nil).closed?
48   end
49
50   def test_author
51     comment = create(:note_comment)
52     assert_nil comment.note.author
53
54     user = create(:user)
55     comment = create(:note_comment, :author => user)
56     assert_equal user, comment.note.author
57   end
58
59   def test_author_ip
60     comment = create(:note_comment)
61     assert_nil comment.note.author_ip
62
63     comment = create(:note_comment, :author_ip => IPAddr.new("192.168.1.1"))
64     assert_equal IPAddr.new("192.168.1.1"), comment.note.author_ip
65   end
66
67   # Ensure the lat/lon is formatted as a decimal e.g. not 4.0e-05
68   def test_lat_lon_format
69     note = build(:note, :latitude => 0.00004 * GeoRecord::SCALE, :longitude => 0.00008 * GeoRecord::SCALE)
70
71     assert_equal "0.0000400", note.lat.to_s
72     assert_equal "0.0000800", note.lon.to_s
73   end
74 end