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