]> git.openstreetmap.org Git - rails.git/blob - test/models/note_test.rb
Add factories for notes and note_comments
[rails.git] / test / models / note_test.rb
1 # -*- coding: utf-8 -*-
2 require "test_helper"
3
4 class NoteTest < ActiveSupport::TestCase
5   fixtures :users, :notes, :note_comments
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 = notes(:open_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 = notes(:open_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 = notes(:open_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 = notes(:closed_note_with_comment)
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, notes(:open_note).visible?
44     assert_equal true, notes(:note_with_hidden_comment).visible?
45     assert_equal false, notes(:hidden_note_with_comment).visible?
46   end
47
48   def test_closed?
49     assert_equal true, notes(:closed_note_with_comment).closed?
50     assert_equal false, notes(:open_note).closed?
51   end
52
53   def test_author
54     assert_nil notes(:open_note).author
55     assert_equal users(:normal_user), notes(:note_with_comments_by_users).author
56   end
57
58   def test_author_ip
59     assert_equal IPAddr.new("192.168.1.1"), notes(:open_note).author_ip
60     assert_nil notes(:note_with_comments_by_users).author_ip
61   end
62 end