]> git.openstreetmap.org Git - rails.git/blob - test/models/note_test.rb
Merge remote-tracking branch 'openstreetmap/pull/1553'
[rails.git] / test / models / note_test.rb
1 # -*- coding: utf-8 -*-
2 require "test_helper"
3
4 class NoteTest < ActiveSupport::TestCase
5   def test_status_valid
6     ok = %w[open closed hidden]
7     bad = %w[expropriated fubared]
8
9     ok.each do |status|
10       note = create(:note)
11       note.status = status
12       assert note.valid?, "#{status} is invalid, when it should be"
13     end
14
15     bad.each do |status|
16       note = create(:note)
17       note.status = status
18       assert !note.valid?, "#{status} is valid when it shouldn't be"
19     end
20   end
21
22   def test_close
23     note = create(:note)
24     assert_equal "open", note.status
25     assert_nil note.closed_at
26     note.close
27     assert_equal "closed", note.status
28     assert_not_nil note.closed_at
29   end
30
31   def test_reopen
32     note = create(:note, :status => "closed", :closed_at => Time.now)
33     assert_equal "closed", note.status
34     assert_not_nil note.closed_at
35     note.reopen
36     assert_equal "open", note.status
37     assert_nil note.closed_at
38   end
39
40   def test_visible?
41     assert_equal true, create(:note, :status => "open").visible?
42     assert_equal true, create(:note, :status => "closed").visible?
43     assert_equal false, create(:note, :status => "hidden").visible?
44   end
45
46   def test_closed?
47     assert_equal true, create(:note, :status => "closed", :closed_at => Time.now).closed?
48     assert_equal false, create(:note, :status => "open", :closed_at => nil).closed?
49   end
50
51   def test_author
52     comment = create(:note_comment)
53     assert_nil comment.note.author
54
55     user = create(:user)
56     comment = create(:note_comment, :author => user)
57     assert_equal user, comment.note.author
58   end
59
60   def test_author_ip
61     comment = create(:note_comment)
62     assert_nil comment.note.author_ip
63
64     comment = create(:note_comment, :author_ip => IPAddr.new("192.168.1.1"))
65     assert_equal IPAddr.new("192.168.1.1"), comment.note.author_ip
66   end
67 end